using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EShang.Common { /// /// 描述特性的读取 /// public static class DescriptionHelper { /// /// 获取枚举的描述 /// /// /// public static string GetEnumDescription(this Enum em) { Type type = em.GetType(); var name = Enum.GetName(type, em); if (name == null) return ""; var field = type.GetField(name); if (field == null) return ""; if (!(Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) is DescriptionAttribute attribute)) { return name; } return attribute.Description; } } }