首页 > Windows开发 > 详细

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

时间:2014-10-24 10:45:13      阅读:275      评论:0      收藏:0      [点我收藏+]

获取:

    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 }); }

 

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

原文:http://www.cnblogs.com/xachary/p/4047605.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!