zoukankan      html  css  js  c++  java
  • C# Attribute 用法备忘

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace MyFirstAttribute
    {
        class Program
        {
            static void Main(string[] args)
            {
                System.Reflection.MemberInfo info=typeof(TestClass);
                MyAttribute myAttribute = Attribute.GetCustomAttribute(info, typeof(MyAttribute)) as MyAttribute;
                Console.WriteLine(myAttribute.Author);
                Console.WriteLine(myAttribute.Time);
                Console.ReadLine();
            }
        }
    
        #region MyAttribute
        [AttributeUsage(AttributeTargets.Class)]
        public class MyAttribute : Attribute
        {
            private string _author;
            private string _time;
    
            public MyAttribute(string author, string time)
            {
                _author = author;
                _time = time;
            }
    
            public string Author
            {
                get { return _author; }
            }
            public string Time
            {
                get { return _time; }
            }
        }
        #endregion
    
    
        [My("zzy", "2009-3-3")]
        class TestClass
        {
    
        }
    }
  • 相关阅读:
    CMS、G1收集器
    一文入门Redis
    一文解析TCP/UDP
    ubuntu官方源
    一、单体架构分析
    netty简介2
    netty简介
    安装vmware tool
    jdk1.8安装(转载)
    HTTP1.0、HTTP1.1 和 HTTP2.0 的区别
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/2840216.html
Copyright © 2011-2022 走看看