Friday, May 11, 2012

Examining .NET 4.0 with C#: ExpandoObject


 I brought up the C#:
1public string Name { getset; }
syntactic sugar, it still isn’t as clean or concise as Ruby:
1class Person
2   attr_accessor :first_name:last_name
3end
or what he envisioned for Java:
1//context of another
2class Person p = new Person();
3p.firstName := "John";
where the getter and setter are automatically appended to the Person object by the compiler.
Well, .NET 4.0 still isn’t quite as cool and concise, but it is getting closer with the introduction of the ExpandoObject. By adding the following using statement:
1using System.Dynamic;
you now get the ability to write code like:
1dynamic p = new ExpandoObject();
2p.firstName = "John";
Oh, and did I mention that you get IntelliSense with it as well?
IntelliSense with ExpandoObject properties.
You still get IntelliSense with ExpandoObject dynamic properties.
When using ExpandoObject(s) with .NET 4.0 and C#, you get IntelliSense for all of the dynamically generated fields.
link: http://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject(v=VS.100).aspx

No comments: