C# 如何在不提及派生类名的情况下返回接口类型?
我正在寻找一种不引用类名的方法,但仍然可以达到预期的效果。 我无法执行ITypedList.GetType(),因为它是一个接口C# 如何在不提及派生类名的情况下返回接口类型?,c#,inheritance,interface,types,C#,Inheritance,Interface,Types,我正在寻找一种不引用类名的方法,但仍然可以达到预期的效果。 我无法执行ITypedList.GetType(),因为它是一个接口 public class DerivedList : ITypedList ... public PropertyDescriptorCollection GetItemProperties() { return TypeDescriptor.GetProperties(typeof(DerivedList)); } ... 我想
public class DerivedList : ITypedList
...
public PropertyDescriptorCollection GetItemProperties()
{
return TypeDescriptor.GetProperties(typeof(DerivedList));
}
...
我想知道这是否可能
干杯,编辑:尝试用没有提到自己类名的东西替换它绝对
public PropertyDescriptorCollection GetItemProperties()
{
return TypeDescriptor.GetProperties(this);
}
绝对
public PropertyDescriptorCollection GetItemProperties()
{
return TypeDescriptor.GetProperties(this);
}
只需在当前实例上调用
GetType
:
return TypeDescriptor.GetProperties(this.GetType());
只需在当前实例上调用
GetType
:
return TypeDescriptor.GetProperties(this.GetType());
我觉得这个问题有点不清楚,但可能就是我。是否尝试替换此行“返回TypeDescriptor.GetProperties(typeof(DerivedList));”用一些没有提到它自己的类名的东西?是的。对不起,如果不清楚的话,我是这里的新手。我觉得这个问题有点不清楚,但可能就是我。是否尝试替换此行“返回TypeDescriptor.GetProperties(typeof(DerivedList));”用一些没有提到它自己的类名的东西?是的。对不起,如果不清楚的话,我是这里的新手。