using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Reflection;
|
using System.Text;
|
|
namespace WIDESEA.Common
|
{
|
public static class EnumTools
|
{
|
/// <summary>
|
/// 获取当前枚举描述
|
/// </summary>
|
/// <param name="enumValue"></param>
|
/// <returns></returns>
|
public static string GetEnumDescription(this Enum enumValue)
|
{
|
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();
|
}
|
}
|
}
|