title: How to check if a generic type definition inherits from another generic type definition
body: <p>I'm trying to check whether an open generic type definition implements some open generic interface. Look at the sample below:</p>
  
  <pre><code>public interface IService&lt;T&gt; { }
  
  public class ServiceImpl&lt;T&gt; : IService&lt;T&gt; { }
  
  private static bool OpenGenericTypeImplementsOpenGenericInterface(
      Type derivedType, Type interfaceType)
  {
      return derivedType.GetInterfaces().Contains(interfaceType);
  }
  
  [TestMethod]
  public void Verify()
  {
      Type openGenericImplementation = typeof(ServiceImpl&lt;&gt;);
  
      Type expectedInterfaceType = typeof(IService&lt;&gt;);
  
      bool implDoesImplementInterface = OpenGenericTypeImplementsOpenGenericInterface(
          openGenericImplementation, expectedInterfaceType);
  
      // This assert fails. Why?
      Assert.IsTrue(implDoesImplementInterface);
  }
  </code></pre>
  
  <p>I found out that the returned type from the <code>Type.GetInterfaces()</code> method does not match the type returned from <code>typeof(IService&lt;&gt;)</code>. I can't figure out why that is and how to correctly validate whether some generic type definition inherits or implements some other generic type definition.</p>
  
  <p>What's going on here and how do I solve fix this problem?</p>