Does Type.GetProperties() guarantee a certain order for its PropertyInfo[] result? Such as returning them in alphabetical order by property name or the order they appear in code. Or is the order undefined?
GetProperties() Returns all the public properties of the current Type.
You can do this by getting an array of all properties from the Type. GetProperties method and then iterating the elements in the array, or you can retrieve the PropertyInfo object that represents the property directly by calling the Type. GetProperty method and specifying the property name.
GetProperties() Method is used to get the properties of the current Type.
From MSDN:
The GetProperties method does not return properties in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which properties are returned, because that order varies.
I think you can sort the array again using "PropertyInfo.MetadataToken" Like this :
Array.Sort(propertyInfos, delegate(PropertyInfo first, PropertyInfo second)
{
return first.MetadataToken.CompareTo(second.MetadataToken);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With