(转载)C# Attribute 用法备忘
2011-11-28 14:26
369 查看
View Code
参考:http://www.cnblogs.com/zzy0471/archive/2009/03/04/1403390.html
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 { } }
参考:http://www.cnblogs.com/zzy0471/archive/2009/03/04/1403390.html
相关文章推荐
- C#中Attribute特性的用法(转载)
- C# Attribute 用法备忘
- [转载]C# ListView用法详解
- @ModelAttribute 用法(完全转载)
- C#中File 类的用法 转载
- 艾伟_转载:C#正则表达式整理备忘
- c#中特性的用法 Attribute (转)
- 转载:C# HashSet 用法
- 转载C#中Trim()、TrimStart()、TrimEnd()的用法
- C#中的Attribute定义及用法
- C#新手入门代码 LINQ TO XML xattribute的用法示例
- 【转载】C#中Using 的几种用法
- C#属性(Attribute)用法实例解析
- C# index of 用法(转载)
- C# 中virtual,override,new 的区别与用法(转载)
- C# List<T>用法 (转载)
- .NET(c#)new关键字的三种用法(转载)
- [转载]C#异步委托的用法 .
- 详解C#中Attribute特性应用 (转载)
- C# lock 、 Monitor Wait、Pulse和PulseAll 的区别和用法(转载)