如何在不提及派生类名的情况下返回接口类型?

时间:2009-05-22 01:41:38

标签: c# inheritance interface types

我正在寻找引用类名的方法,但仍然达到了预期的效果。 我不能做ITypedList.GetType(),因为它是一个接口。

public class DerivedList : ITypedList  
...  
public PropertyDescriptorCollection GetItemProperties()  
{  
    return TypeDescriptor.GetProperties(typeof(DerivedList));  
}  
...  

我想知道这是否可行。

干杯,
编辑:尝试用不提及它自己的类名的东西替换它

2 个答案:

答案 0 :(得分:4)

绝对......

    public PropertyDescriptorCollection GetItemProperties()
    {
        return TypeDescriptor.GetProperties(this);  
    }

答案 1 :(得分:0)

只需在当前实例上调用GetType

return TypeDescriptor.GetProperties(this.GetType());