Click here to Skip to main content
12,509,509 members (56,547 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

5.5K views
Posted

Reflection & Order of discovered properties

, 3 Oct 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
In .NET environement Reflection provides several methods to obtain information about any type from the type system. One of these methods is GetProperties method which retrieves a list of all the properties of a given type. This method returns an array of PropertyInfo objects.
In .NET environement Reflection provides several methods to obtain information about any type from the type system. One of these methods is GetProperties method which retrieves a list of all the properties of a given type. This method returns an array of PropertyInfo objects.
PropertyInfo[] propListInfo = type.GetProperties();
In most cases you don't care, but the order of the properties does not have to be the same if you run this method several times. This is well described in the documentation of this method. Microsoft also states, that your code should not be depending on the order of the properties obtained.

I had a very nice example of a bug resulting from the misuse of this method. A ObjectComparer

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jan Fajfr
Software Developer (Junior) OCTO Technology
Czech Republic Czech Republic
Writing software at ITG RFQ-hub.
LinkedIn
Blog
GitHub
Articles at OCTO blog

You may also be interested in...

Pro

Comments and Discussions

 
SuggestionI know it wasn't the point, but this could be more efficient Pin
Matt T Heffron3-Oct-12 13:41
memberMatt T Heffron3-Oct-12 13:41 
GeneralRe: I know it wasn't the point, but this could be more efficient Pin
Jan Fajfr4-Oct-12 10:45
memberJan Fajfr4-Oct-12 10:45 
GeneralRe: I know it wasn't the point, but this could be more efficient Pin
Matt T Heffron4-Oct-12 11:24
memberMatt T Heffron4-Oct-12 11:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160927.1 | Last Updated 3 Oct 2012
Article Copyright 2012 by Jan Fajfr
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid