title: Checking if Type or instance implements IEnumerable regardless of Type T
body: <p>I'm doing a heavy bit of reflection in my current project, and I'm trying to provide a few helper methods just to keep everything tidy.</p>
  
  <p>I'd like to provide a pair of methods to determine if a type or instance implements <code>IEnumerable</code> – regardless of the type <code>T</code>. Here is what I have at the moment:</p>
  
  <pre><code>public static bool IsEnumerable(this Type type)
  {
      return (type is IEnumerable);
  }
  
  public static bool IsEnumerable(this object obj)
  {
      return (obj as IEnumerable != null);
  }
  </code></pre>
  
  <p>When I test them using</p>
  
  <pre><code>Debug.WriteLine("Type IEnumerable:   " + typeof(IEnumerable).IsEnumerable());
  Debug.WriteLine("Type IEnumerable&lt;&gt;: " + typeof(IEnumerable&lt;string&gt;).IsEnumerable());
  Debug.WriteLine("Type List:          " + typeof(List&lt;string&gt;).IsEnumerable());
  Debug.WriteLine("Type string:        " + typeof(string).IsEnumerable());
  Debug.WriteLine("Type DateTime:      " + typeof(DateTime).IsEnumerable());
  Debug.WriteLine("Instance List:      " + new List&lt;string&gt;().IsEnumerable());
  Debug.WriteLine("Instance string:    " + "".IsEnumerable());
  Debug.WriteLine("Instance DateTime:  " + new DateTime().IsEnumerable());
  </code></pre>
  
  <p>I get this as the result:</p>
  
  <pre><code>Type IEnumerable:   False
  Type IEnumerable&lt;&gt;: False
  Type List:          False
  Type string:        False
  Type DateTime:      False
  Instance List:      True
  Instance string:    True
  Instance DateTime:  False
  </code></pre>
  
  <p>The type method doesn't appear to work at all – I had expected a <code>true</code> for the direct <code>System.Collections.IEnumerable</code> match at least.</p>
  
  <p>I'm aware that <code>string</code> is technically enumerable, albeit with a few caveats. Ideally in this case, however, I'd need the helper method to return <code>false</code> for it. I just need the instances with a defined <code>IEnumerable&lt;T&gt;</code> type to return <code>true</code>.</p>
  
  <p>I've probably just missed something fairly obvious – can anyone point me in the right direction?</p>