码迷,mamicode.com
首页 > Windows程序 > 详细

C#Attribute

时间:2015-05-12 08:08:42      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Attribute
{
    using System;
    class Program
    {
        static void Main(string[] args)
        {
            HelpAttribute helpAttribute;
            foreach (var attr in typeof(AnyClass).GetCustomAttributes(true))
            {
                helpAttribute = attr as HelpAttribute;
                if (null != helpAttribute)
                {
                    Console.WriteLine("AnyClass Description:{0}",helpAttribute.Description);
                }
            }
            Console.ReadKey();
        }
    }
    [AttributeUsage(AttributeTargets.Class,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 a do-nothing class",Name="jikexueyuan")]
    public class AnyClass
    { 
        
    }
}

 

C#Attribute

标签:

原文地址:http://www.cnblogs.com/heisaijuzhen/p/4496326.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!