using System;
|
using System.Collections.Generic;
|
using System.ComponentModel.DataAnnotations;
|
using System.Linq;
|
using System.Text;
|
|
namespace IStation.Extensions
|
{
|
/// <summary>
|
/// 枚举拓展
|
/// </summary>
|
public static class EnumExtension
|
{
|
/// <summary>
|
/// 根据System.ComponentModel.DataAnnotations下的DisplayAttribute特性获取显示文本
|
/// </summary>
|
public static string GetDisplayText(this Enum t)
|
{
|
var t_type = t.GetType();
|
var fieldName = Enum.GetName(t_type, t);
|
var objs = t_type.GetField(fieldName).GetCustomAttributes(typeof(DisplayAttribute), false);
|
return objs.Length > 0 ? ((DisplayAttribute)objs[0]).Name : null;
|
}
|
|
|
|
}
|
|
}
|