using System; using System.ComponentModel; using System.Reflection; namespace DeviceRepair.Models { /// /// 枚举类 扩展类 /// public static class Extensions { /// /// 获取枚举类型的描述 /// /// /// public static string ToDescription(this EnumOperationType enumeration) { Type type = enumeration.GetType(); MemberInfo[] memInfo = type.GetMember(enumeration.ToString()); if (null != memInfo && memInfo.Length > 0) { object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false); if (null != attrs && attrs.Length > 0) return ((DescriptionAttribute)attrs[0]).Description; } return enumeration.ToString(); } /// /// 获取枚举类型的描述 /// /// /// public static string ToDescription(this DeviceWarrantyRequestFormStatus enumeration) { Type type = enumeration.GetType(); MemberInfo[] memInfo = type.GetMember(enumeration.ToString()); if (null != memInfo && memInfo.Length > 0) { object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false); if (null != attrs && attrs.Length > 0) return ((DescriptionAttribute)attrs[0]).Description; } return enumeration.ToString(); } /// /// 获取枚举类型的描述 /// /// /// public static string ToDescription(this DeviceRunningStatus enumeration) { Type type = enumeration.GetType(); MemberInfo[] memInfo = type.GetMember(enumeration.ToString()); if (null != memInfo && memInfo.Length > 0) { object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false); if (null != attrs && attrs.Length > 0) return ((DescriptionAttribute)attrs[0]).Description; } return enumeration.ToString(); } } }