EnumHelper.cs 618 B

123456789101112131415161718192021
  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 ShakerManger.Tools
  8. {
  9. internal static class EnumHelper
  10. {
  11. public static string Description(this Enum e)
  12. {
  13. if (e == null || !e.GetType().IsEnum) return "";
  14. return (e.GetType()?
  15. .GetField(e.ToString())?
  16. .GetCustomAttributes(typeof(DescriptionAttribute), false)
  17. .FirstOrDefault() as DescriptionAttribute)?.Description ?? e.ToString();
  18. }
  19. }
  20. }