[英]How to return an interface type without mentioning the derived class name?
我正在尋找一種不引用類名的方法,但仍能達到預期的效果。 我不能做ITypedList.GetType(),因為它是一個接口。
public class DerivedList : ITypedList
...
public PropertyDescriptorCollection GetItemProperties()
{
return TypeDescriptor.GetProperties(typeof(DerivedList));
}
...
我想知道這是否可行。
干杯,
編輯:嘗試用不提及它自己的類名的東西替換它
絕對......
public PropertyDescriptorCollection GetItemProperties()
{
return TypeDescriptor.GetProperties(this);
}
只需在當前實例上調用GetType
:
return TypeDescriptor.GetProperties(this.GetType());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.