Professional C# 4 and .NET 4
by Christian Nagel, Bill Evjen, Jay Glynn, Karli Watson, Morgan Skinner
Chapter 12. Dynamic Language Extensions
WHAT'S IN THIS CHAPTER?
Understanding the Dynamic Language Runtime
The
dynamictypeThe DLR ScriptRuntime
DynamicObjectExpandoObject
The growth of languages such as Ruby, Python, and the increased use of JavaScript have intensified interest in dynamic programming. In previous versions of the .NET Framework, the var keyword and anonymous methods started C# down the "dynamic" road. In version 4, the dynamic type was added. Although C# is still a statically typed language, these additions give it the dynamic capabilities that some developers are looking for.
In this chapter, you'll look at the dynamic type and the rules for using it. You'll also see what an implementation of DynamicObject looks like and how it can be used.
DYNAMIC LANGUAGE RUNTIME
The dynamic capabilities of C# 4 are part of the Dynamic Language Runtime (DLR). The DLR is a set of services that is added to the CLR to allow the addition of dynamic languages such as Ruby and Python. It also allows C# to take on some of the same dynamic capabilities that these dynamic languages have.
There is a version of the DLR that is open source and resides on the CodePlex web site. This same version is included with the .NET 4 Framework, with some additional support for language implementers.
In the .NET Framework, the DLR is found in the System.Dynamic namespace as well as a few additional classes in the System.Runtime.CompilerServices namespace.
IronRuby and IronPython, which are open source versions ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access