tags:

views:

28

answers:

1

Hi,

To get the properties is not big deal, but I don´t want to get the properties inherited from another class. The bindingFlags option doesn´t have any option of this kind.

Is that possible ?

cheers

+2  A: 

Use BindingFlags.DeclaredOnly with your Type.GetProperties call in order to specify to just get the properties from the specified type.

For example, to get all non-static properties on a type without looking up it's hierarchy, you could do:

var properties = theType.GetProperties(
                          BindingFlags.Public | 
                          BindingFlags.NonPublic | 
                          BindingFlags.Instance | 
                          BindingFlags.DeclaredOnly);
Reed Copsey
Thanks Reed, worked fine, I was trying without the 'Public' BindingFlags, just the 'Instance' one will return 0 properties... school boy error. cheers !
2Fast4YouBR