zoukankan      html  css  js  c++  java
  • 获取enum的Description

    using System;
    using System.Reflection;
    using System.ComponentModel;
    using System.Collections.Specialized; 
        class Program
        {
            static void Main(string[] args)
            {
                Type type = typeof(DescriptionAttribute);
                foreach (FieldInfo fi in typeof(CustomerRankType).GetFields())
                {
                    object[] arr = fi.GetCustomAttributes(type, true);
                    if (arr.Length > 0)
                    {
                        Console.WriteLine(((DescriptionAttribute)arr[0]).Description);
                    }
                }
    Console.ReadLine();
            }
        }
        /// <summary>
        /// 用户等级枚举
        /// </summary>
        [Serializable]
        public enum CustomerRankType
        {
            [Description("游客")]
            
            Unknown = 0,
            [Description("初级会员")]
            
            JuniorMember = 1,
            
            [Description("青铜会员")]
            BronzeMember = 2,
            
            [Description("白银会员")]
            SilverMember = 3,
            
            [Description("黄金会员")]
            GoldMember = 4,
            
            [Description("钻石会员")]
            DiamondMember = 5,
            
            [Description("皇冠会员")]
            CrownMember = 6,
            
            [Description("至尊会员")]
            EggEmperor = 7
        }
  • 相关阅读:
    增量式爬虫 Scrapy-Rredis 详解及案例
    scrapy-redis使用以及剖析
    为什么代码要写到匿名自执行函数中?
    Vue组件第三天--webpack
    Vue组价通信
    Vue组件第一天
    pip3 install pycryptohome
    selenium 安装与 chromedriver安装
    解决:'chromedriver' executable needs to be in PATH问题
    如何在VS Code中编写Python
  • 原文地址:https://www.cnblogs.com/bober/p/2257235.html
Copyright © 2011-2022 走看看