Getting attributes of Enum's value

后端 未结 25 2543
慢半拍i
慢半拍i 2020-11-22 00:35

I would like to know if it is possible to get attributes of the enum values and not of the enum itself? For example, suppose I have the following <

25条回答
  •  情深已故
    2020-11-22 01:07

    And if you want the full list of names you can do something like

    typeof (PharmacyConfigurationKeys).GetFields()
            .Where(x => x.GetCustomAttributes(false).Any(y => typeof(DescriptionAttribute) == y.GetType()))
            .Select(x => ((DescriptionAttribute)x.GetCustomAttributes(false)[0]).Description);
    

提交回复
热议问题