using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace JSMachine.WMS.Infrastructure { public static class EnumExtension { /// /// 获取枚举描述属性值 /// /// /// public static string GetDescription(this Enum @enum) { Type type = @enum.GetType(); string name = Enum.GetName(type, @enum); if (string.IsNullOrWhiteSpace(name)) return @enum.ToString(); FieldInfo field = type.GetField(name); DescriptionAttribute des = field?.GetCustomAttribute(); if (des == null) return @enum.ToString(); return des.Description; } } }