0
class CBase
{
object A {get;set;}
object B {get;set;}
}
class CDerived : CBase
{
object X {get;set}
object Y {get;set;}
}
我試圖獲得第一級屬性。對於上面的例子,預期的屬性是X和Y,而不是A和B.使用下面的代碼,我得到了所有的屬性{A,B,X,Y}。有沒有沒有屬性簽名的解決方案?關於最高級別屬性的思考
foreach (var propertyInfo in typeof(CDerived).GetProperties())
{
propertyInfo.SetValue(model, row[propertyInfo.Name], null);
}
http://stackoverflow.com/questions/1544979/c-reflection-getproperties-with-bindingflags-declaredonly – 2010-09-20 22:57:48