EnumExtentions.cs 790 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace NXWMS.Code.Extends
  9. {
  10. /// <summary>
  11. ///
  12. /// </summary>
  13. public static class EnumExtentions
  14. {
  15. public static string Description(this Enum t)
  16. {
  17. string value = t.ToString();
  18. FieldInfo field = t.GetType().GetField(value);
  19. object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
  20. if (objs == null || objs.Length == 0)
  21. return value;
  22. DescriptionAttribute descriptionAttribute = (DescriptionAttribute)objs[0];
  23. return descriptionAttribute.Description;
  24. }
  25. }
  26. }