我自定义了一个Attribute,现在我是用这个Atribute去声明一个类,发现只有在这个类从ContextBoundObject继承时,才能够使用自定义Attribute的功能,而我看到DllImport、Conditional、Obsolete之类的Attribute,并不需要被声明的类从ContextBoundObject继承,请问为什么?

解决方案 »

  1.   

    ContextBoundObject在Attribute中起到什么样的作用呢?
      

  2.   

    在定义你自己的attribute的时候需声明他使用的范围
    [AttributeUsage(AttributeTargets.All)]适用任何类型
      

  3.   

    http://www.cnblogs.com/Winston/archive/2008/12/01/1344881.htmlhttp://www.cnblogs.com/freebird92/archive/2006/12/27/605047.html
      

  4.   

    Attribute 类去MSDN上一查就知道了。
      

  5.   

    ...Attribute 可用性范围是类型(如类,字段,属性..) 好象与继承某个类没有任何关系吧~!反射你标记的哪个地方看看咯!
      

  6.   

    Attribute ... 我觉得这个比较像狗皮膏药~~~贴上。。就成~~