title: vb.net method constraints
body: <p>I have a class which I have marked as MustInherit (called BasePage), with a generic method that is marked as MustOverride:</p>
  
  <pre><code>Protected MustOverride Function SaveData(Of T As {BaseClass})(ByVal item As T) As T
  </code></pre>
  
  <p>What I want to do is force the users of this method to only supply a type of BaseClass, or anything derived from it.  Also, when a class derives from BasePage, it should work on only one derived class from BaseClass:</p>
  
  <pre><code>Protected Overrides Function SaveData(Of T As BaseClass)(ByVal item As T) As T
    Dim grad As DerivedClass = CType(item, DerivedClass)
  
    Return grad
  End Function
  </code></pre>
  
  <p>However, when I try to do the cast, it flags up the following error:</p>
  
  <pre><code>Value of type 'T' cannot be converted to 'DerivedClass'.
  </code></pre>
  
  <p>All the documentation I have read suggests that this should work.  However, it's not a big problem if it doesn't work, as I can work around by making a non-generic method that only accepts BaseClass.</p>
  
  <p>Any ideas?</p>