您的位置:首页 > 编程语言 > C#

C#遍历获取枚举的值,名和属性

2014-10-24 10:13 183 查看
获取:

Type type = typeof(ParamServiceType);
var values = Enum.GetValues(type);
for (int i = 0; i < values.Length; i++)
{
var v = values.GetValue(i);
var member = type.GetMember(v.ToString());
DescriptionAttribute des = (DescriptionAttribute)System.Attribute.GetCustomAttribute(member[0], typeof(DescriptionAttribute));
//以下代码是业务需求
serviceRoot.children.Add(new ServiceTree()
{
id = (int)v,//取int值
text = des.Description,//取属性值
state = "open",
attributes = v.ToString(),//取名
children = null
});
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: