锐腾搅拌上料功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ICSSoft.Frame.Data.Entity;
  6. namespace ICSSoft.Frame.Common
  7. {
  8. public static class EnumExtfunction
  9. {
  10. public static string GetDescription<Attr>(this Enum em) where Attr : AttrDescription
  11. {
  12. Type enumType = em.GetType();
  13. var name = Enum.GetName(enumType, em);
  14. if (name == null)
  15. return string.Empty;
  16. object[] objs = enumType.GetField(name).GetCustomAttributes(typeof(Attr), false);
  17. if (objs == null || objs.Length == 0)
  18. return string.Empty;
  19. Attr attr = objs[0] as Attr;
  20. return attr.Description;
  21. }
  22. public static string GetDescription(this Enum em)
  23. {
  24. Type enumType = em.GetType();
  25. var name = Enum.GetName(enumType, em);
  26. if (name == null)
  27. return string.Empty;
  28. object[] objs = enumType.GetField(name).GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
  29. if (objs == null || objs.Length == 0)
  30. return string.Empty;
  31. System.ComponentModel.DescriptionAttribute attr = objs[0] as System.ComponentModel.DescriptionAttribute;
  32. return attr.Description;
  33. }
  34. }
  35. }