Does Type.GetProperties() guarantee a certain order for the PropertyInfo[] result?
Does Type.GetProperties() 开发者_如何学Goguarantee 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?
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);
});
精彩评论