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 GetEnumDic(Type enumType)
        {
            Dictionary dic =new Dictionary();
            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;
        }

  

你可能感兴趣的:(C# 枚举显示中文)