我有这样的枚举:
enum MyEnum{
[Order(1)]
ElementA = 1,
[Order(0)]
ElementB = 2,
[Order(2)]
ElementC = 3
}
Run Code Online (Sandbox Code Playgroud)
我想列出按我编写的自定义顺序属性排序的元素,以便我得到一个排序的项目列表.
我得到描述属性,但只是这样的一个元素:
FieldInfo fi = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
Run Code Online (Sandbox Code Playgroud)
它可能是相同的但需要在所有枚举上工作并返回列表或其他排序的枚举.