using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
namespace TProduct.Extensions
{
///
/// 枚举拓展
///
public static class EnumExtension
{
///
/// 根据System.ComponentModel.DataAnnotations下的DisplayAttribute特性获取显示文本
///
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;
}
}
}