在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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 { } }
|
请发表评论