Get all properties of current class and base class

410 Views Asked by At

I have 2 classes (lets say "BaseItem" and "ChildItem") with several internal properties. In the BaseClass i have defined a method which should read out all of this properties with

PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this);

or

PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this.GetType()); 

When i call this method in an instance of "ChildItem", i get only the properties that are defined in "ChildItem". What can i do to get also the the properties of "BaseItem"?

Regards

Dave

2

There are 2 best solutions below

0
On BEST ANSWER

For internal properties (as clarified in the question comments), although not indicated (they're internal for a reason), you can use:

var internalProperties = GetType().GetProperties(
                            BindingFlags.Instance | 
                            BindingFlags.NonPublic |
                            BindingFlags.Public));

It's the flag BindingFlags.NonPublic that needs to be applied.

1
On

You could just cast it to BaseItem and do GetProperties() separately..