Connecting Tech Pros Worldwide Forums | Help | Site Map

Getting list of Properties using Reflection

Dawid Mostert
Guest
 
Posts: n/a
#1: Nov 22 '05
Hi,

I'm trying to get a list of properties from a hierarchy of classes,
using reflection.

Using Type.GetProperties(), I get the list back in "reverse hierarchy
order" (derived class properties before parent class properties)

Using TypeDescriptor.GetProperties(), the order of the returned
properties is also wrong.

I used the XmlSerializer to test my classes, and the properties was
written out correctly (Parent class before derived class).

What can I do to get a list of properties in the correct order (Parent
class before inherited class)?

Thanks for the help,
Dawid Mostert
d_mostert@nospam.hotmail.com

Mattias Sjögren
Guest
 
Posts: n/a
#2: Nov 22 '05

re: Getting list of Properties using Reflection


[color=blue]
>What can I do to get a list of properties in the correct order (Parent
>class before inherited class)?[/color]

Get only the properties that are declared in the class itself (specify
BindingFlags.DeclaredOnly), and manually walk the inheritance
hierarchy.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dawid Mostert
Guest
 
Posts: n/a
#3: Nov 22 '05

re: Getting list of Properties using Reflection


Thanks!

Sounds like a good idea... Any other (less manual ;) ) options?

How do I combine 2 arrays into 1?

Regards,
Dawid

Mattias Sjögren wrote:[color=blue][color=green]
>>What can I do to get a list of properties in the correct order (Parent
>>class before inherited class)?[/color]
>
>
> Get only the properties that are declared in the class itself (specify
> BindingFlags.DeclaredOnly), and manually walk the inheritance
> hierarchy.
>
>
>
> Mattias
>[/color]
Closed Thread