WEBINAR:
On-Demand
Application Security Testing: An Integral Part of DevOps
# 4.0 includes a number of enhancements and additions, including:
- Support for dynamic lookup
- Support for both named and optional parameters
- Enhanced COM Interop features
- Support for variance
This article takes a look at the first two items in that list, provides examples, and shows how you can take advantage of them in your applications. A future article covers the last two items.
As you may be able to divine from the terms in the list, some of C#'s new features are tied into Microsoft's new Dynamic Language Runtime (DLR) environment—a new feature of the .NET Framework that enables dynamic languages to reside side-by-side and interoperate with statically typed languages.
Author's Note: To execute the code examples discussed in this article, you should have Visual Studio 2010 Beta 1 or later installed in your system. |
Understanding the DLR
The DLR is built on top of the Common Language Runtime (CLR) and opens the door for a common set of technologies and tools to interoperate inside a common framework. Dynamically typed languages such as Python, Ruby, and JavaScript can reside alongside familiar statically typed .NET languages such as C#, Managed C++, and Visual Basic. The CLR provides a common platform where statically typed languages (e.g. C#, VB) can reside and interoperate, while the DLR sits on top of the CLR and provides a common platform for dynamically typed languages to reside and interoperate.
The DLR adds a set of services that facilitate dynamic language implementations on .NET's managed platform. These services include support for a dynamic type system, a standard hosting model, and fast dynamic code generation. In addition, the DLR lets dynamic and static languages interoperate bi-directionally.
To support the DLR, the .NET Framework 4.0 contains a new System.Dynamic namespace. The Dynamic Language Runtime contains three layers (see Figure 1):
- The .NET Language Integration Layer
- The Dynamic Language Runtime Code Components
- Language Binders
The services the DLR provides include:
- Dynamic Method Dispatch
- Dynamic Code Generation
- Hosting API
With that brief introduction to the DLR, you can move on to explore C#'s new features.