0
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);
}
jack-london
  • 1,599
  • 3
  • 21
  • 42

1 Answers1

2

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

Quintin Robinson
  • 81,193
  • 14
  • 123
  • 132