我有以下两类(型号),一个是基类,另一个是子类:如何确定属性是否属于基类或子类动态使用反射的泛型类型?
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。我认为你的意思是使用Reflection而不是泛型? – StuartLC
https://stackoverflow.com/questions/12667219/reflection-exclude-all-attributes-from-base-class-and-specific-attribute-from-al – Ric