22 lines
660 B
C#
22 lines
660 B
C#
using System.ComponentModel;
|
|
using System.Reflection;
|
|
|
|
namespace IM.Commons
|
|
{
|
|
public static class EnumHelper
|
|
{
|
|
/// <summary>
|
|
/// 获取枚举的 Description 描述信息
|
|
/// </summary>
|
|
public static string GetDescription(this Enum value)
|
|
{
|
|
FieldInfo? field = value.GetType().GetField(value.ToString());
|
|
if (field == null) return value.ToString();
|
|
|
|
DescriptionAttribute? attribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
|
|
|
|
return attribute == null ? value.ToString() : attribute.Description;
|
|
}
|
|
}
|
|
}
|