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 "";
            }

  • 相关阅读:
    计算机书籍.网址
    MVC是必知必用的
    技术
    三色旗帜分类
    巴斯卡三角形
    Centos安装wine等组件的问题
    some software that is used to speed up your system
    驾照考试系统之流程图
    用静态成员函数调用非静态成员变量
    MFC 进度条控件
  • 原文地址:https://www.cnblogs.com/happyday56/p/3456195.html
Copyright © 2011-2022 走看看