导航

2012年2月1日

摘要: 原文:http://msdn.microsoft.com/zh-cn/library/z919e8tw.aspx如果没有检索自定义特性的信息和对其进行操作的方法,则定义自定义特性并将其放置在源代码中就没有意义。 使用反射,可检索用自定义特性定义的信息。 主要方法是 GetCustomAttributes,它返回对象数组,这些对象在运行时等效于源代码特性。 此方法具有多个重载版本。 有关更多信息,请参见 Attribute。特性规范,如:[Author("P. Ackerman", version = 1.1)]class SampleClass在概念上等效于:Author 阅读全文

posted @ 2012-02-01 15:02 Jessie.M 阅读(236) 评论(0) 推荐(0) 编辑

摘要: 1 using System; 2 using System.Reflection; 3 4 class Module1 5 { 6 7 public static void Main() 8 { 9 // This variable holds the amount of indenting that 10 // should be used when displaying each line of information. 11 Int32 indent = 0; 12 // Display info... 阅读全文

posted @ 2012-02-01 13:21 Jessie.M 阅读(288) 评论(0) 推荐(0) 编辑

摘要: 整理自原文:【MSDN文章】编写自定义属性、AttributeUsageAttribute 类 、AttributeTargets 枚举另注:property和attribute的区别:property是指类向外提供的数据区域,其中有get和set访问器来提供对数据的读写,即用于类中字段的存取;attribute是描述对象在编译时或运行时属性的,有时也叫“特性”,用于标识类、方法等程序元素的附加性质。一、AttributeUsageAtttribute属性的使用定义您自己的属性 (Attribute) 类时,可通过在属性 (Attribute) 类上放置 AttributeUsageAttri 阅读全文

posted @ 2012-02-01 09:39 Jessie.M 阅读(540) 评论(0) 推荐(0) 编辑