If you are an edgy developer then you should be already knowing about the new version of .Net and about the keyword ‘dynamic’. C# 4.0 is adding support for the dynamic keyword, which introduces some aspects of dynamic languages to C#. I was reading on the some early bird posts pushed by some geeky folks upon the topic, and was sort of looking for a good opportunity to squeeze it into coding. After doing some research I found some scenarios which I thought it would work great with the dynamic type and also some areas it didn’t worked as expected.
Root is a public static property I used in sample which points to textbox in the main window.
1 - Hello World in dynamic.
This example demonstrates a ‘Hello World’ in dynamic.
2 - Convertions:
Dynamic eliminates the use of unboxing completely. We don’t require the value to be Casted if we do an assignment from a higher grade to lower grade.
3 - COM Interop with Office.
The above feature creates the flexibility for dynamic to use it with COM interop.
4 - Using dynamic with Reflection:
This was the best part I liked while trying with this new syntax. Dynamic did a wonderful job here which helped me bypass some steps and of course result in some level of performance improvement.
Unreferenced Remote Assembly.
5 - Using dynamic syntax to map an xml file:
6 - Call for static method – Do not work.
And here is some exception which comes with dynamic. This is something found not to be working with dynamic and it looks like Microsoft is planning to give support for this only on next version.
Well, you guys can also add the comments here and links to new cases where we can use dynamic. This would definitely help people who are new into C# 4.0.
Here is the sample which I worked available for download.
External Links/ References:
I found some folks who already did the paper work for me which I avoided the theory part. You can see the dynamic and .Net 4.0 Insides here in these links.
C# 4.0: Dynamic Programming - Explains the basics and layers of DLR –Dynamic Language Runtime.
Video Cast from MS DLR Development Team – Video explains the challenges and some technical insides for DLR.
Programming Gallery Article: http://www.programminggallery.com/article_details.php?article_id=126