博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#获取枚举描述
阅读量:4356 次
发布时间:2019-06-07

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

using System;using System.Collections.Generic;using System.ComponentModel;using System.Reflection;using System.Text;namespace JFJT.GemStockpiles.Helpers{    public static class EnumHelper    {        ///         /// 根据值得到中文备注        ///         ///         ///         /// 
public static String GetEnumDesc(this Type e, int? value) { FieldInfo[] fields = e.GetFields(); for (int i = 1, count = fields.Length; i < count; i++) { if ((int)System.Enum.Parse(e, fields[i].Name) == value) { DescriptionAttribute[] EnumAttributes = (DescriptionAttribute[])fields[i]. GetCustomAttributes(typeof(DescriptionAttribute), false); if (EnumAttributes.Length > 0) { return EnumAttributes[0].Description; } } } return ""; } }}

调用

 

 

转载于:https://www.cnblogs.com/Cein/p/9151821.html

你可能感兴趣的文章
月底发票确认后台
查看>>
并查集(Union-Find)
查看>>
Mybatis联合查询记录,左连接参数操作
查看>>
tf.argmax()以及axis解析
查看>>
Day07 jdk5.0新特性&Junit&反射
查看>>
软件工程-团队作业4
查看>>
import与link的具体区别(转)
查看>>
python中基于descriptor的一些概念(下)
查看>>
CSS下拉菜单
查看>>
Tomcat 8熵池阻塞变慢详解(putty)
查看>>
新入行程序员应知的十个秘密
查看>>
小Z爱序列
查看>>
项目导入及发布
查看>>
gpg:no valid openpgp data found
查看>>
BZOJ4259 残缺的字符串 FFT
查看>>
Razor语法大全
查看>>
十一、多线程——6-线程通信
查看>>
十三、类的加载和反射——2-类加载器
查看>>
双向链表的删除操作
查看>>
快速排序 - 数据结构和算法96
查看>>