开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜