title: In VB, How do you force an inherited class to use an attribute on the class?
body: <p>I'm trying to force an inherited class to use a custom attribute.  I'm creating a class library where the user who wants to create an item will do so, but be forced to add an attribute (or visual studio will automatically add the default attribute) to their inherited class.  Here is what I'm hoping to achieve:  </p>
  
  <p>BaseClass.vb: </p>
  
  <pre><code>&lt;CustomAttribute(10)&gt; _
  Public Class BaseClass
  
  End Class
  </code></pre>
  
  <p>MyClass.vb:</p>
  
  <pre><code>&lt;CustomAttribute(12)&gt; _
  Public Class MyClass
      Inherits BaseClass
  
      Public Sub New()
           Mybase.New()
      End Sub
  
  End Class
  </code></pre>
  
  <p>So the thought is that much like when you mark a function as "MustOverride" and then the inherited class must override the function, I want the attribute to be "MustOverride" causing the inherited class to specify the value.</p>
  
  <p>I've tried this, and it will work, but it would be much cleaner if I could use attributes: </p>
  
  <p>BaseClass.vb: </p>
  
  <pre><code>Public MustInherit Class BaseClass
  
     Public MustOverride ReadOnly Property CustomAttribute() As String
  
  End Class
  </code></pre>
  
  <p>MyClass.vb:</p>
  
  <pre><code>Public Class MyClass
      Inherits BaseClass
  
      Public Sub New()
           Mybase.New()
      End Sub
  
      Public Overrides ReadOnly Property CustomAttribute() As String
          Get
               Return "testing"
          End Get
      End Property
  End Class
  </code></pre>
  
  <p>Thank you for any help you can provide. </p>
  
  <p>Scott</p>