zoukankan      html  css  js  c++  java
  • 反射获取枚举的属性注释

     public enum AccountType
        {       
            [Description("支付宝充值")]
            ALIPAY = 1,
      
            [Description("银联充值")]
            UNIONPAY = 2

    }

    public static string GetEnumName<T>(int value) where T : new()
            {
                Type t = typeof(T);
                foreach (MemberInfo mInfo in t.GetMembers())
                {
                    if (mInfo.Name == t.GetEnumName(value))
                    {
                        foreach (Attribute attr in Attribute.GetCustomAttributes(mInfo))
                        {
                            if (attr.GetType() == typeof(DescriptionAttribute))
                            {
                                return ((DescriptionAttribute)attr).Description;
                            }
                        }
                    }
                }
                return "";
            }

  • 相关阅读:
    51nod1260
    51nod1327
    51nod1342
    51nod1479
    LOJ6088
    51nod1634
    51nod1778
    JAVA循环结构学校上机经常遇到的几题 笔记
    B. The Number of Products(Codeforces Round #585 (Div. 2))
    A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题
  • 原文地址:https://www.cnblogs.com/happyday56/p/3456195.html
Copyright © 2011-2022 走看看