Anonymous Type is nothing but the type which gets defined by CLR (not you). So that type is as rich as any other normal type. Probably the conventional way to find the components of an Anonymous Type through reflection would be clearer to us,
static void Main()
{
//Anonymous Type
var anyType = new
IntID = 1,
StringName = "Wriju"
};
Type t = anyType.GetType();
PropertyInfo[] pi = t.GetProperties();
foreach (PropertyInfo p in pi)
//Get the name of the prperty
Console.WriteLine(p.Name);
}
//Using LINQ get all the details of Property
var query = from p in t.GetProperties()
select p;
ObjectDumper.Write(query);
Namoskar!!!
PingBack from http://msdnrss.thecoderblogs.com/2007/10/25/c-30-anonymous-type-and-net-reflection-hand-in-hand/
Welcome to the thirty-fifth edition of Community Convergence. This week we have an interview with C#