"To pass an anonymous type, or a collection that contains anonymous types, outside a method boundary, you must first cast the type to object."
This isn't entirely true. Consider this helper method:
public static List<T> ListOfType<T>(this T type)
{
return new List<T>();
}
This allows you to write:
var v = new { Amount = 108, Message = "Hello" };
var listOfV = ListOfType(v);
listOfV.Add(v);
I just passed a new strongly-typed List<some_anonymous_type> out of a method without casting it to object.
You can also cast object to an anonymous type using the following helper method:
T Cast<T>(object obj, T type)
{
return (T)obj;
}
So even if you return the anonymous type from a method by casting to object, you can use it strongly typed like this:
var v = Cast(ThisReturnsAnonymousTypeAsObject(), new { Amount = 0, Message = "" });
if(v.Message == "Hello") ...
See "Can't return anonymous type from method? Really?" for more details:
http://tomasp.net/blog/cannot-return-anonymous-type-from-method.aspx