title: Specify required base class for .NET attribute targets
body: <p>I tried to create a custom .NET attribute with the code below but accidentally left off the subclass.  This generated an easily-fixed compiler error shown in the comment.</p>
  
  <pre><code>// results in compiler error CS0641: Attribute 'AttributeUsage' is 
  // only valid on classes derived from System.Attribute
  [AttributeUsage(AttributeTargets.Class)]
  internal class ToolDeclarationAttribute
  {
      internal ToolDeclarationAttribute()
      {
      }
  }
  </code></pre>
  
  <p>My question is how does the compiler know the <code>[AttributeUsage]</code> attribute can only be applied to a subclass of <code>System.Attribute</code>?  Using .NET Reflector I don't see anything special on the <code>AttributeUsageAttribute</code> class declaration itself.  Unfortunately this might just be a special case generated by the compiler itself.</p>
  
  <pre><code>[Serializable, ComVisible(true), AttributeUsage(AttributeTargets.Class, Inherited=true)]
  public sealed class AttributeUsageAttribute : Attribute
  {
      ...
  </code></pre>
  
  <p>I would like to be able to specify that my custom attribute can only be placed on subclasses of a particular class (or interface).  Is this possible?</p>