using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; /// /// 枚举扩展 /// public static class EnumExtension { /// /// 获取枚举描述 /// /// 枚举类型 /// public static string GetEnumDisplayName(this Enum enumType) { try { Type type = enumType.GetType(); var field = type.GetField(Enum.GetName(type, enumType)); var attr = field.GetCustomAttribute(); if (attr == null || string.IsNullOrWhiteSpace(attr.Name)) return enumType.ToString(); else return attr.Name; } catch { return string.Empty; } } }