zoukankan      html  css  js  c++  java
  • C# 枚举显示中文

    转自:http://www.cnblogs.com/yank/archive/2011/09/08/EnumDisplayInChinese.html

     
    using System;
    using System.ComponentModel;
    
    public enum TimeOfDay
    {
        [Description("上午")]
        Moning,
        [Description("下午")]
        Afternoon,
        [Description("晚上")]
        Evening,
    };
    

      

      public static Dictionary<string, string> GetEnumDic(Type enumType)
            {
                Dictionary<string, string> dic =new Dictionary<string, string>();
                FieldInfo[] fieldinfos = enumType.GetFields();
                foreach (FieldInfo field in fieldinfos)
                {
                    if (field.FieldType.IsEnum)
                    {
                        Object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
    
                        dic.Add(field.Name, ((DescriptionAttribute)objs[0]).Description);
                    }
    
                }
    
                return dic;
            }
    

      

  • 相关阅读:
    Tomcat安装与配置
    模板方法模式
    观察者模式
    访问者模式
    策略模式
    迭代器模式
    状态模式
    访问者模式
    备忘录模式
    解释器模式
  • 原文地址:https://www.cnblogs.com/wdw31210/p/5209774.html
Copyright © 2011-2022 走看看