zoukankan      html  css  js  c++  java
  • Attributes(1):反射Attribute并输出

    using System;

    using System.Reflection;

    using System.Text;

     

    namespace Attribute01

    {

    class Program

    {

    static void Main(string[] args)

    {

    Type type = typeof(Test);

    foreach (CodeReviewAttribute att in

    type.GetCustomAttributes(typeof(CodeReviewAttribute), false))

    {

    Console.WriteLine("Reviewer: {0}", att.Reviewer);

    Console.WriteLine("Date:{0}", att.Date);

    Console.WriteLine("Comment: {0}", att.Comment);

    }

     

    Console.ReadLine();

    }

    }

    //目标定位于class

    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]

    public class CodeReviewAttribute : System.Attribute

    {

    private string reviewer;

    private string date;

    private string comment;

     

    public CodeReviewAttribute(string reviewer, string date)

    {

    this.reviewer = reviewer;

    this.date = date;

    }

     

    public string Comment

    {

    get { return (comment); }

    set { this.comment = value; }

     

    }

     

    public string Date

    {

    get { return this.date; }

    set { this.date = value; }

    }

     

    public string Reviewer

    {

    get { return this.reviewer; }

    set { this.reviewer = value; }

    }

    }

     

     

    [CodeReview("PSM", "2013-09-07", Comment="BUG Fixed 3055")]

    [CodeReview("GJH", "2013-09-08", Comment = "BUG Fixed 2088")]

    class Test

    {

    }

    }

  • 相关阅读:
    匈牙利算法-二分图的最大匹配
    UOJ 407(IOI2018 D1T3)
    UOJ 460
    UOJ 405(IOI2018 D1T1)
    Codeforces 1110E
    2.文件结构
    1.常用快捷键
    Python3.x和Python2.x的差异
    javascript 常用内置对象
    94. Binary Tree Inorder Traversal(非递归实现二叉树的中序遍历)
  • 原文地址:https://www.cnblogs.com/pengshaomin/p/3305713.html
Copyright © 2011-2022 走看看