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
        }
  • 相关阅读:
    iOS
    iOS
    iOS
    OpenGLES入门笔记四
    OpenGLES入门笔记三
    AVPlayer无法播放
    阿里云TTS重播报pointer being freed was not allocated错误
    [AVAssetWriter startWriting] Cannot call method when status is 1
    HTTP load failed (error code: -1009) / NSURLConnection finished with error
    在iPhone5上起始页卡着不动
  • 原文地址:https://www.cnblogs.com/bober/p/2257235.html
Copyright © 2011-2022 走看看