31 lines
854 B
C#
31 lines
854 B
C#
using DeviceRepair.Models.Attr;
|
|
using System;
|
|
using System.Reflection;
|
|
|
|
namespace DeviceRepair.Models
|
|
{
|
|
public static class ExtendFuncHelper
|
|
{
|
|
/// <summary>
|
|
/// 获取枚举的描述文本信息
|
|
/// </summary>
|
|
/// <param name="em"></param>
|
|
/// <returns></returns>
|
|
public static string Description(this System.Enum em)
|
|
{
|
|
Type type = em.GetType();
|
|
FieldInfo fd = type.GetField(em.ToString());
|
|
if (fd == null)
|
|
return string.Empty;
|
|
object[] attrs = fd.GetCustomAttributes(typeof(EnumDescriptionAttribute), false);
|
|
string name = string.Empty;
|
|
foreach (EnumDescriptionAttribute attr in attrs)
|
|
{
|
|
name = attr.Desciption;
|
|
}
|
|
return name;
|
|
}
|
|
|
|
}
|
|
}
|