title: Convert Object to Collection
body: <p>I have the situation where I am given an object and need to:</p>
  
  <ul>
  <li>Determine if that object is a single object or a collection (Array, List, etc)</li>
  <li>If it is a collection, step though the list.</li>
  </ul>
  
  <p>What I have so far. Testing for IEnumerable does not work. And the conversion to IEnumerable only works for non-primitive types.</p>
  
  <pre><code>static bool IsIEnum&lt;T&gt;(T x)
  {
      return null != typeof(T).GetInterface("IEnumerable`1");
  }
  static void print(object o)
  {
      Console.WriteLine(IsIEnum(o));       // Always returns false
      var o2 = (IEnumerable&lt;object&gt;)o;     // Exception on arrays of primitives
      foreach(var i in o2) {
          Console.WriteLine(i);
      }
  }
  public void Test()
  {
      //int [] x = new int[]{1,2,3,4,5,6,7,8,9};
      string [] x = new string[]{"Now", "is", "the", "time..."};
      print(x);       
  }
  </code></pre>
  
  <p>Anyone know how to do this?</p>