using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace OASystem.Domain.Enums { public static class EnumHelper { //--extension /// /// 获取当前枚举描述 /// /// /// public static string GetEnumDescription(this Enum enumValue) { try { Type type = enumValue.GetType(); MemberInfo[] memInfo = type.GetMember(enumValue.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 enumValue.ToString(); } catch (Exception) { return ""; } } //根据值获取枚举方法 public static Enum GetEnumByValue(Type enumType, string value) { return Enum.Parse(enumType, value) as Enum; } } }