title: How do I tell whether a Type implements IList<>?
body: <p>I want to write a method that uses Reflection to tell whether a given Type implements <code>IList&lt;T&gt;</code>. For example:</p>
  
  <pre><code>IsGenericList(typeof(int))                       // should return false
  IsGenericList(typeof(ArrayList))                 // should return false
  IsGenericList(typeof(IList&lt;int&gt;))                // should return true
  IsGenericList(typeof(List&lt;int&gt;))                 // should return true
  IsGenericList(typeof(ObservableCollection&lt;int&gt;)) // should return true
  </code></pre>
  
  <p>In my usage, I can assume that the type will always be an instantiated generic type (or something that's not generic at all).</p>
  
  <p>Unfortunately, this isn't as easy as it ought to be. The obvious solution:</p>
  
  <pre><code>public bool IsGenericList(Type type)
  {
      return typeof(IList&lt;&gt;).IsAssignableFrom(type);
  }
  </code></pre>
  
  <p>doesn't work; it always returns false. Apparently non-instantiated generic types like <code>IList&lt;&gt;</code> don't implement IsAssignableFrom the way I'd expect them to: <code>IList&lt;&gt;</code> is not assignable from <code>List&lt;T&gt;</code>.</p>
  
  <p>I've also tried this:</p>
  
  <pre><code>public bool IsGenericList(Type type)
  {
      if (!type.IsGenericType)
          return false;
      var genericTypeDefinition = type.GetGenericTypeDefinition();
      return typeof(List&lt;&gt;).IsAssignableFrom(genericTypeDefinition);
  }
  </code></pre>
  
  <p>I.e., turn <code>type</code> into its non-instantiated generic, like <code>IList&lt;int&gt;</code> -> <code>IList&lt;&gt;</code>, and then try IsAssignableFrom again. That will return true when type is an instantiated <code>IList&lt;T&gt;</code> such as <code>IList&lt;int&gt;</code>, <code>IList&lt;object&gt;</code>, etc. But it returns false for classes that implement <code>IList&lt;T&gt;</code> such as <code>List&lt;int&gt;</code>, <code>ObservableCollection&lt;double&gt;</code>, etc., so apparently <code>IList&lt;&gt;</code> is not assignable from <code>List&lt;&gt;</code>. Again, not what I would expect.</p>
  
  <p>How do I go about writing IsGenericList and making it work as in the above examples?</p>