Welcome to MSDN Blogs Sign in | Join | Help

Wriju's BLOG

.NET and everything
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!!!

 

Posted: Friday, October 26, 2007 1:57 by wriju

Comments

Charlie Calvert's Community Blog said:

Welcome to the thirty-fifth edition of Community Convergence. This week we have an interview with C#

# November 5, 2007 2:02 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker