zoukankan      html  css  js  c++  java
  • 特性(attribute)

     自定义特性

    class Program
        {
            static void Main(string[] args)
            {
    
                Console.ReadLine();
            }
        }
        [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)]
        public class HelpAttribute : Attribute
        {
            protected string description;
            public HelpAttribute(string description_in)
            {
                this.description = description_in;
            }
            public string Description
            {
                get
                {
                    return this.description;
                }
            }
            public string name
            { get; set; }
        }
        [Help("this is do Nothing Class", name = "zhangsan")]
        public class AnyClass
        {
    
        }

     获取特性

    HelpAttribute helpAttribute;
                foreach (var attr in typeof(AnyClass).GetCustomAttributes(true))
                {
                    helpAttribute = attr as HelpAttribute;
                    if (null != helpAttribute)
                    {
                        Console.WriteLine("AnyClass Description:{0}", helpAttribute.Description);
                    }
                }
  • 相关阅读:
    stl测试
    noip2017逛公园
    比赛
    莫队算法
    noi.ac 第五场第六场
    重排DL
    bzoj2870
    异象石(就是sdio宝藏那题)
    Genius ACM
    模板复习
  • 原文地址:https://www.cnblogs.com/handsomer/p/4553729.html
Copyright © 2011-2022 走看看