的類型,我有以下類獲取泛型參數
public interface InterfaceBase
{
}
public class ImplementA:InterfaceBase
{
}
public class ImplementB:InterfaceBase
{
}
public void TestImplementType<T>(T obj) where T: InterfaceBase
{
}
如何推斷T是什麼是否ImplementA或ImplementB?我試着用
typeof(T) is ImplementA
但是這個表達式總是被評估爲false。
編輯:我如何將obj投射到ImplementA或ImplementB?
再次,不說是t從ImplementA派生 - 只會談AB out obj的特殊價值。 TestImplementType(新的ImplementA())將通過(根據實際問題)它不應該。 –
2008-10-28 07:06:20