我有以下兩類(型號),一個是基類,另一個是子類:如何確定屬性是否屬於基類或子類動態使用反射的泛型類型?
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