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.

29 line
779B

  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 GpsCardGatewayPosition.Common.Extension
  9. {
  10. public static class EnumExt
  11. {
  12. public static string ToDescription(this Enum value)
  13. {
  14. Type type = value.GetType();
  15. string name = Enum.GetName(type, value);
  16. if (name == null)
  17. {
  18. return null;
  19. }
  20. FieldInfo field = type.GetField(name);
  21. DescriptionAttribute attribute = System.Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
  22. return (attribute?.Description) + "";
  23. }
  24. }
  25. }