【发布时间】:2018-02-22 01:23:10
【问题描述】:
我有以下两个类(模型),一个是基类,另一个是子类:
public class BaseClass
{
public string BaseProperty{get;set;}
}
public class ChildClass: BaseClass
{
public string ChildProperty{get;set;}
}
在应用程序中,我使用泛型动态调用ChildClass
List<string> propertyNames=new List<string>();
foreach (PropertyInfo info in typeof(T).GetProperties())
{
propertyNames.Add(info.Name);
}
在这里,在propertyNames 列表中,我也获得了BaseClass 的财产。我只想要那些在子类中的属性。这可能吗?
我尝试了什么?
【问题讨论】:
-
不错的q。我认为您的意思是使用反射而不是泛型?
标签: c# .net generics inheritance reflection