class Program
{
static void Main(string[] args)
{
string str= DB.write.ToDescription();
Console.WriteLine(str);
Console.ReadKey();
}
}
public enum DB{
[Description("读")]
write=,
[Description("写")]
read=
}
public static class MyException
{
/// <summary>
/// 获取枚举类型的描述
/// </summary>
/// <param name="enumeration"></param>
/// <returns></returns>
public static string ToDescription(this Enum enumeration)
{
Type type = enumeration.GetType();
MemberInfo[] memInfo = type.GetMember(enumeration.ToString());
if (null != memInfo && memInfo.Length > )
{
object[] attrs = memInfo[].GetCustomAttributes(typeof(DescriptionAttribute), false);
if (null != attrs && attrs.Length > )
return ((DescriptionAttribute)attrs[]).Description;
}
return enumeration.ToString();
}
}