开发者

Does Type.GetProperties() guarantee a certain order for the PropertyInfo[] result?

开发者 https://www.devze.com 2022-12-08 01:00 出处:网络
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

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);
  });
0

精彩评论

暂无评论...
验证码 换一张
取 消