title: Open generic type inheritance dynamic identification in C#
body: <p>When I have two non-generic <code>Type</code> objects <code>a</code> and <code>b</code>, I can easily verify whether a is assignable from b by using the <code>a.IsAssignableFrom(b)</code> function.</p>
  
  <pre><code>class ClassBase { }
  class ClassDerived : ClassBase { }
  ...
  typeof(ClassBase).IsAssignableFrom(typeof(ClassDerived)) //returns true
  </code></pre>
  
  <p>Now say I have two generic interfaces:</p>
  
  <pre><code>interface IBase&lt;T&gt; { }
  interface IDerived&lt;T&gt; : IBase&lt;T&gt; { }
  </code></pre>
  
  <p>If I close them down, I can do the same thing as before, with exactly the same behaviour, e.g.</p>
  
  <pre><code>typeof(IBase&lt;object&gt;).IsAssignableFrom(typeof(IDerived&lt;object&gt;)) //returns true
  </code></pre>
  
  <p>In fact, any <code>T</code> that can be used to close down <code>IDerived</code> can also be used to close down <code>IBase</code> and <code>IBase&lt;T&gt;</code> is assignable from <code>IDerived&lt;T&gt;</code> (for that particular T). </p>
  
  <p>However, </p>
  
  <pre><code>typeof(IBase&lt;&gt;).IsAssignableFrom(typeof(IDerived&lt;&gt;)) //returns false
  </code></pre>
  
  <p>I sort of have an idea why that might be so (they can be closed down on different types and thus get inconvertible?). I understand that a function that does return true in this case is thus somewhat different. The question is: "Is <code>IBase&lt;T&gt;</code> assignable from <code>IDerived&lt;T&gt;</code> for every valid <code>T</code>?" (thanks to <a href="https://stackoverflow.com/users/743382/hvd">hvd</a>)</p>
  
  <p><strong>What I thought of doing</strong> is closing the generics and then asking whether they are assignable. But to be general, I would need to close down under the most generic type(s) <code>b</code> can take and that could be a) ugly, b) quite hard to do.</p>
  
  <p>Another approach is to go up the implementation/inheritance tree on <code>b</code> and try comparing it to <code>a</code>.</p>
  
  <p>My <strong>question</strong> is whether there is an easier way of doing this even in general cases.</p>
  
  <p><strong>Motivation:</strong> general interest, as I don't actually need this at the end. However, the initial need for this came while I was using Ninject with open and closed generics and I needed to resolve whether an open generic class can be cast to an open generic interface (class).</p>