博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
枚举处理
阅读量:7200 次
发布时间:2019-06-29

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

//=======================================================================================

/****************************************************************************************
*
* 文件说明:
* 作者:
* 创始时间:2017/11/9 17:23:01
* 创建说明:
*****************************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Manjinba.Communication.Common.Utils

{
public static class EnumUtil
{
private static Dictionary<string, Dictionary<string, string>> enumCache;

private static Dictionary<string, Dictionary<string, string>> EnumCache

{
get
{
if (enumCache == null)
{
enumCache = new Dictionary<string, Dictionary<string, string>>();
}
return enumCache;
}
set { enumCache = value; }
}

public static string GetEnumText(this Enum en)

{
string enString = string.Empty;
if (null == en) return enString;
var type = en.GetType();
enString = en.ToString();
if (!EnumCache.ContainsKey(type.FullName))
{
var fields = type.GetFields();
Dictionary<string, string> temp = new Dictionary<string, string>();
foreach (var item in fields)
{
var attrs = item.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attrs.Length == 1)
{
string v = ((DescriptionAttribute)attrs[0]).Description;
temp.Add(item.Name, v);
}
}
EnumCache.Add(type.FullName, temp);
}
if (EnumCache.ContainsKey(type.FullName))
{
if (EnumCache[type.FullName].ContainsKey(enString))
{
return EnumCache[type.FullName][enString];
}
}
return enString;
}
}
}

转载于:https://www.cnblogs.com/Nine4Cool/p/10540655.html

你可能感兴趣的文章
函数的堆栈
查看>>
有趣网址之家 – 收藏全球最有趣的网站
查看>>
Javascript 严格模式详解
查看>>
HttpWatch详解
查看>>
【反射】——Autofac 类型注册
查看>>
杭电2059
查看>>
liunx系统top命令详解
查看>>
访问控制(public,protected,private)
查看>>
hihocoder Counting Islands II(并查集)
查看>>
Codeforces Round #165 (Div. 1) Greenhouse Effect(DP)
查看>>
vs05字节对齐问题又一不小心就弄去了我一个下午的时间
查看>>
PHP-掌握基本的分布式架构思想
查看>>
CentOS7 下安装 Java 8 [wget]
查看>>
particles.js中文开发手册
查看>>
VS2010去除蓝色小点
查看>>
linux-Centos7安装php
查看>>
spring boot 学习(七)小工具篇:表单重复提交
查看>>
Android Activity与Fragment生命周期
查看>>
VBA 如何检测一个中文字符串是否包含在另一个字符串中
查看>>
[转]百度Appollo无人车Perception Module 分析
查看>>