123456789101112131415161718 |
- using System;
- using System.ComponentModel;
- using System.Linq;
- namespace ShakerApp.Tools
- {
- public static class EnumHelper
- {
- public static string Description<T>(this T e) where T:Enum
- {
- if (e == null || !e.GetType().IsEnum) return "";
- return (e.GetType()?
- .GetField(e.ToString())?
- .GetCustomAttributes(typeof(DescriptionAttribute), false)
- .FirstOrDefault() as DescriptionAttribute)?.Description ?? e.ToString();
- }
- }
- }
|