• 代码对象转文字描述,适合分类,类别对象


    直接上代码:
    using System.ComponentModel;
    using System.Runtime.Serialization;
    using System.Reflection;
    using System.Diagnostics;
    using System.Collections.Specialized;
    using System.Text;

    namespace MvcApp.Controllers
    {
        [HandleError]
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                Type type = typeof(DescriptionAttribute);
                StringBuilder str = new StringBuilder();
                str.AppendLine("代码对象转文字描述:");
                foreach (FieldInfo fi in typeof(CustomerRankType).GetFields())
                {
                    object[] arr = fi.GetCustomAttributes(type, true);
                    if (arr.Length > 0)
                    {
                        str.AppendLine(((DescriptionAttribute)arr[0]).Description);
                        // nvc.Add(fi.Name, ((DescriptionAttribute)arr[0]).Description);
                    }
                }
                ViewData["Message"] = str.ToString();

                return View();
            }

            public ActionResult About()
            {
                return View();
            }
        }
        /// <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
        }
    }
  • 相关阅读:
    程序的链接
    Graphviz 画图的一些总结
    C表达式中的汇编指令
    epoll(2) 源码分析
    epoll(2) 使用及源码分析的引子
    eventfd(2) 结合 select(2) 源码分析
    poll(2) 源码分析
    select 源码分析
    kfifo
    程序的机器级表示:寻址方式、指令及栈的运行机制
  • 原文地址:https://www.cnblogs.com/bober/p/2344035.html
Copyright © 2020-2023  润新知