Does GetCustomAttributes() preserve the attribute order in .NET?

前端 未结 4 1422
-上瘾入骨i
-上瘾入骨i 2020-12-11 01:17

The title pretty much says it all. When I\'m doing some reflection through my classes, will the MemberInfo.GetCustomAttributes() method preserve the order of attributes on a

4条回答
  •  心在旅途
    2020-12-11 01:56

    I'd put a single extra (optional) value in the MenuItemAttribute constructor, which is "order" or "priority":

    [MenuItem(0, "Company", "Clients", "Orders")]
    [MenuItem(1, "Foo", "Bar", "Baz")]
    

    I'm not saying it would be pretty, but it would effectively allow you to specify the ordering.

提交回复
热议问题