文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>通过枚举值获取枚举属性文本

通过枚举值获取枚举属性文本

时间:2011-03-15  来源:杨永辉

 public static string GetEnumOptText(Type type, int value)
{
FieldInfo[] fields
= type.GetFields();
for (int i = 1, count = fields.Length; i < count; i++)
{

FieldInfo field
= fields[i];
if (((int)Enum.Parse(type, field.Name)).ToString() == value.ToString())
{
object[] objs = field.GetCustomAttributes(typeof(EnumTextValueAttribute), false);
if (objs == null || objs.Length == 0)
{
return field.Name;
}
else
{
EnumTextValueAttribute da
= (EnumTextValueAttribute)objs[0];
return da.Text;
}
}
}
return "";
}
相关阅读 更多 +
排行榜 更多 +
茶叶蛋大冒险免费版

茶叶蛋大冒险免费版

休闲益智 下载
全民帮帮她

全民帮帮她

休闲益智 下载
屋顶旅行

屋顶旅行

休闲益智 下载