Como crear una lista generica de tipos anonimos

por Admin el 2/26/2011 5:00:00 AM

Visto en el blog de Kiril Osenkov, muy util para generar dinamicamente colecciones de tipos anonimos en framework 4.

 

  static void Main(string[] args)
{
var Customer = new { FirstName = "John", LastName = "Doe" };
var customerList = MakeList(Customer);

customerList.Add(new { FirstName = "Bill", LastName = "Smith" });
}

public static List<T> MakeList<T>(T itemOftype)
{
List<T> newList = new List<T>();
return newList;
}