反射获取枚举的属性注释
 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 "";
        }
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号