title: VB.NET Generic constraints and subclasses
body: <p>Consider the following extension method:</p>
  
  <pre><code>    &lt;Extension()&gt; _
      Public Function Satisfies(Of T)(ByVal subject As T, ByVal specification As ISpecification(Of T)) As Boolean
          Return specification.IsSatisfiedBy(subject)
      End Function
  </code></pre>
  
  <p>This works as expected if subject is the exact class being operated on by the specification. However, if the specification is examining the super-class of T, this extension will not work unless subject is explicitly cast to the super-class. Is there a way I can avoid this? So far, the best I've been able to come up with is:</p>
  
  <pre><code>    &lt;Extension()&gt; _
      Public Function Satisfies(Of T As Class, K As Class)(ByVal subject As T, ByVal specification As ISpecification(Of K)) As Boolean
          Return specification.IsSatisfiedBy(TryCast(subject, K))
      End Function
  </code></pre>
  
  <p>But I can't help but think there's a better way....</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Since I (apparently) can't get this to work exactly as I'd like in VB.NET due to limitations in the language itself, is my second attempt the safest/most efficient way to do this?</p>