zoukankan      html  css  js  c++  java
  • 在C#中读取枚举值的描述属性

    枚举:
    public enum EnumLanugage
    {
        [System.ComponentModel.Description("中文")]
        Chinese,
        English
    }
    
    获取值描述的方法:
    public string GetEnumDescription(Enum enumValue)
    {
        string str = enumValue.ToString();
        System.Reflection.FieldInfo field = enumValue.GetType().GetField(str);
        object[] objs = field.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
        if (objs == null || objs.Length == 0) return str;
        System.ComponentModel.DescriptionAttribute da = (System.ComponentModel.DescriptionAttribute)objs[0];
        return da.Description;
    }
    
    调用 GetEnumDescription(EnumLanguage.Chinese) 后 将返回“中文”
    

      

  • 相关阅读:
    poj1581
    poj3094
    poj2196
    poj1003
    poj2262
    poj1083
    poj3299
    poj2739
    poj1552
    js 获取元素高度和宽度
  • 原文地址:https://www.cnblogs.com/XuPengLB/p/6243775.html
Copyright © 2011-2022 走看看