博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
反射相关函数获取枚举描述函数
阅读量:7230 次
发布时间:2019-06-29

本文共 1258 字,大约阅读时间需要 4 分钟。

public static string GetEnumDescription(Enum enumValue)            {                string value = enumValue.ToString();                FieldInfo field = enumValue.GetType().GetField(value);                object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false);    //获取描述属性                if (objs.Length == 0)    //当描述属性没有时,直接返回名称                    return value;                DescriptionAttribute descriptionAttribute = (DescriptionAttribute)objs[0];                return descriptionAttribute.Description;            }
PropertyInfo[] peroperties = typeof(companyEnum).GetProperties(BindingFlags.Public | BindingFlags.Instance);            foreach (PropertyInfo property in peroperties)            {                object[] objs = property.GetCustomAttributes(typeof(DescriptionAttribute), true);                if (objs.Length > 0)                {                    ControlFiledData cfd = new ControlFiledData();                    cfd.comname = "txt" + property.Name;                    cfd.labtext = ((DescriptionAttribute)objs[0]).Description;                    // Console.WriteLine("{0}: {1}", property.Name, ((DescriptionAttribute)objs[0]).Description);                    ListData.Add(cfd);                }            }

 

转载地址:http://wvdfm.baihongyu.com/

你可能感兴趣的文章
JavaScript 复习之 Object对象的相关方法
查看>>
JAVA之流程控制语句
查看>>
Spring Boot(1)
查看>>
Winodws 10 美化与调优
查看>>
apache安装及多域名解析及域名代理
查看>>
什么是自动化运维 ? 自动化运维的设计思路以及实战
查看>>
Python练习实例100例(持续更新中)
查看>>
非父组件通信
查看>>
Electron系列文章-主进程与渲染进程
查看>>
高性能缓存服务器 nuster v1.8.8.2 和 v1.7.11.2 发布
查看>>
教你快速入门ES6
查看>>
Python 爬虫十六式 - 第六式:JQuery的假兄弟-pyquery
查看>>
宜昌a货翡翠,包头a货翡翠
查看>>
【微信事业群】趣味面试算法题
查看>>
保守的国美再一次进击社交电商,前途未卜?
查看>>
git
查看>>
Python学习教程(Python学习路线):Python 3—手动创建迭代器
查看>>
说说如何在 Virtual Box 中新建 CentOS 虚拟机
查看>>
Cordova + Vue 实现点击两次退出应用
查看>>
JAVA 多用户商城系统b2b2c-Spring Cloud Stream 介绍
查看>>