• 反射获取枚举的属性注释


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

  • 相关阅读:
    Element Plus表单resetFields重置表单无效
    thinkphp6通过中间件设置跨域
    centos7安装jdk
    面试
    行测-逻辑填空
    行测-语句表达
    行测-片段阅读
    行测-四大文明古国
    基于 OAuth2.0 协议的单点登录系统方案设计
    性能测试知识点+流程
  • 原文地址:https://www.cnblogs.com/happyday56/p/3456195.html
Copyright © 2020-2023  润新知