title: Generic inherited type restriction in C#
body: <p>I have an inelegant solution for what I need, but am looking for an elegant solution to replace it.</p>
  
  <p>The following code doesn't compile, but represents what I would like to do:</p>
  
  <pre><code>interface IWebService
  {
  }
  
  abstract class BaseClient&lt;T&gt;
  {
  }
  
  class SpecializedClient : BaseClient&lt;IWebService&gt;
  {
  }
  
  class ClientHelper&lt;T&gt; where T : BaseClient&lt;*&gt;
  {
  }
  </code></pre>
  
  <p>Where the <code>T</code> in <code>ClientHelper&lt;T&gt;</code> is any class that extends <code>BaseClient</code> regardless of the templated type passed in.</p>
  
  <p>The inelegant solution I found is:</p>
  
  <pre><code>class ClientHelper&lt;T, U&gt; where T : BaseClient&lt;U&gt; {}
  </code></pre>
  
  <p>The reason this becomes inelegant is my project ends up with a class similar to:</p>
  
  <pre><code>class MyClass&lt;A, B, C, D, E, F, G&gt; where A  : MyBaseClass&lt;B, C, D, E, F, G&gt;
  </code></pre>
  
  <p>All the way down to the base class that takes a single type.  Is this simply the cost of having a complex inheritance tree of generic classes or is there a simpler way to do this while retaining type restrictions on the templated types?</p>