views:

22

answers:

1
class CBase
{
 object A {get;set;}
 object B {get;set;}
}

class CDerived : CBase
{
 object X {get;set}
 object Y {get;set;}
}

I'm trying to get first level properties. For the example above, intended properties are X and Y, not A and B. With the following code i'm getting all the properties {A,B,X,Y}. Is there any solution without attribute signing.

foreach (var propertyInfo in typeof(CDerived).GetProperties())
{
 propertyInfo.SetValue(model, row[propertyInfo.Name], null);
}
+2  A: 

Try using the DeclaredOnly binding flag in your GetProperties call. This should limit the properties returned to the inheritance (class) level specified.

Quintin Robinson
http://stackoverflow.com/questions/1544979/c-reflection-getproperties-with-bindingflags-declaredonly
jack london