Recursively find all objects of type System.Web.UI.Pair in an object array
You might consider making this an extension method on Pair instead of object.  You could simplify it to this:

public static IEnumerable&lt;Pair&gt; Flatten(this Pair p, List&lt;Pair&gt; toBuild = null)
{
   if (toBuild == null)
      toBuild = new List&lt;Pair&gt;();

   if (p.First is Pair)
   {
      (p.First as Pair).Flatten(toBuild);
   }
   else if (p.First is IEnumerable)
   {
      foreach (object o in (p.First as IEnumerable).OfType&lt;object&gt;().Where(ob =&gt; ob is Pair))
      {
         (o as Pair).Flatten(toBuild);
      }
   }

   //repeat for p.Second

  toBuild.Add(p);
  return toBuild;
}


You can use it like this:

var result = myPair.Flatten();


Or on an IEnumerable&lt;Pair&gt;:

var result = myList.SelectMany(p =&gt; p.Flatten());


Or on a regular IEnumerable:

var result = myList.OfType&lt;object&gt;().Where(o =&gt; o is Pair)
  .SelectMany(p =&gt; (p as Pair).Flatten());