• 枚举处理


    //=======================================================================================
    /****************************************************************************************
    *
    * 文件说明:
    * 作者:
    * 创始时间: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;
    }
    }
    }

  • 相关阅读:
    pandas_处理异常值缺失值重复值数据差分
    【C语言】输入10个人的成绩,求平均值
    【Markdown】新手快速入门基础教程
    【Python】 平方根
    【Python】 数字求和
    【Python】文件下载小助手
    【Python爬虫程序】抓取MM131美女图片,并将这些图片下载到本地指定文件夹。
    【Python】爬虫原理
    C语言最重要的知识点(电子文档)
    【Python】一些函数
  • 原文地址:https://www.cnblogs.com/Nine4Cool/p/10540655.html
Copyright © 2020-2023  润新知