title: Determine if object derives from collection type
body: <p>I want to determine if a generic object type ("T") method type parameter is a collection type.  I would typically be sending T through as a Generic.List but it could be any collection type as this is used in a helper function.</p>
  
  <p>Would I be best to test if it implements IEnumerable&lt;T&gt;?</p>
  
  <p>If so, what would the code look like?</p>
  
  <p><strong>Update 14:17 GMT+10 Possibly extending on a solution <a href="http://www.devcurry.com/2009/03/determine-if-object-implements.html" rel="noreferrer">here</a> (however only works for List&lt;T>'s not IEnumerable&lt;T>'s when it should if List derives ?)</strong></p>
  
  <pre><code>T currentObj;    
  // works if currentObj is List&lt;T&gt;
  currentObj.GetType().GetGenericTypeDefinition() == typeof(List&lt;&gt;)
  // does not work if currentObj is List&lt;T&gt;
  currentObj.GetType().GetGenericTypeDefinition() == typeof(IEnumerable&lt;&gt;)
  </code></pre>