Tuesday, February 26, 2013

New Modifier: 6 Simple New(er) C#/.Net features you may have missed

New Modifier: 6 Simple New(er) C#/.Net features you may have missed:

'via Blog this'


ExpandoObject


An object you can dynamically add members to.  Lack of practical examples aside, there is a lot of possibilities because you can nest ExpandoObjects to create structured data (think XML-like/HTML-like).  You can think of ExpandoObjects as a Dictionary on steroids.  ExpandoObject is apart of the much bigger support for the Dynamic type introduced in C# 4.

   1:  public void ExpandoObject()
   2:          {
   3:              dynamic sampleObject = new System.Dynamic.ExpandoObject();
   4:              sampleObject.Test = "TestDynamic";
   5:              sampleObject.InvokeExpandoObject = new Action(() => Console.Write(sampleObject.Test));
   6:              sampleObject.InvokeExpandoObject.Invoke();
   7:          }

No comments: