HeadersHelper.cs 733 B

1234567891011121314151617181920212223
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace ServerLib
  8. {
  9. public static class HeadersHelper
  10. {
  11. public static string GetDescription(this Enum value)
  12. {
  13. var valueType = value.GetType();
  14. var memberName = Enum.GetName(valueType, value);
  15. if (memberName == null) return null;
  16. var fieldInfo = valueType.GetField(memberName);
  17. var attribute = Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute));
  18. if (attribute == null) return null;
  19. return (attribute as DescriptionAttribute).Description;
  20. }
  21. }
  22. }