定制特性学习笔记 我的定制特性学习笔记 using System;using System.Collections.Generic;using System.Text;using System.Reflection;using System.Diagnostics;namespace AttrTestControl{ [MyAttr("构造中",Desc="属性")] public class Program { static void Main(string[] args) { Assembly a = Assembly.LoadFrom(Process.GetCurrentProcess().ProcessName + ".exe"); Type type = typeof(Program); foreach (Attribute attr in type.GetCustomAttributes(true)) { MyAttrAttribute newAttr = attr as MyAttrAttribute; if(newAttr!=null) Console.WriteLine(newAttr.Desc); } Console.ReadLine(); } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)] class MyAttrAttribute : Attribute { private string _Desc; /**//// <summary> /// Desc /// </summary> public string Desc { get { return _Desc; } set { _Desc = value; } } public MyAttrAttribute(string sDesc) { _Desc = sDesc; } }} 发表于 2007-06-29 15:57 Ray Lynn 阅读(272) 评论(1) 编辑 收藏 举报 相关文章: 2021-08-28 2021-06-22 2022-02-10 2021-09-19 2021-04-19 2022-01-06 2021-10-23 2021-07-23