EnumHelper.cs 800 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. namespace IMCS_CCS.Utils
  6. {
  7. public class EnumHelper
  8. {
  9. public static string GetDescription(Enum value)
  10. {
  11. if (value == null)
  12. {
  13. throw new ArgumentException("value");
  14. }
  15. string description = value.ToString();
  16. var fieldInfo = value.GetType().GetField(description);
  17. var attributes =
  18. (EnumDescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(EnumDescriptionAttribute), false);
  19. if (attributes != null && attributes.Length > 0)
  20. {
  21. description = attributes[0].Description;
  22. }
  23. return description;
  24. }
  25. }
  26. }