C# 3.0 : Anonymous Type and .NET Reflection Hand-in-Hand
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!!!
Comments
Anonymous
October 25, 2007
PingBack from http://msdnrss.thecoderblogs.com/2007/10/25/c-30-anonymous-type-and-net-reflection-hand-in-hand/Anonymous
November 05, 2007
Welcome to the thirty-fifth edition of Community Convergence. This week we have an interview with C#