Datasheet

776
Running with the Dynamic Language Runtime
Here is the compiled C# code:
class C
{
[return: Dynamic]
public object MyMethod([Dynamic] object d)
{
if (MyMethodo__SiteContainer0.p__Site1 == null)
{
MyMethodo__SiteContainer0.p__Site1 =
CallSite<Func<CallSite, object, object>>
.Create(new CSharpCallPayload(
CSharpCallFlags.None, “Foo”,
typeof(object), null,
new CSharpArgumentInfo[] {
new CSharpArgumentInfo(CSharpArgumentInfoFl
ags.None,
null) }));
}
return MyMethodo__SiteContainer0.p__Site1
.Target(MyMethodo__SiteContainer0.p__Site1, d);
}
[CompilerGenerated]
private static class MyMethodo__SiteContainer0
{
public static CallSite<Func<CallSite, object,
object>> p__Site1;
}
}
Yeah, that’s what I said, too. I am not going to even begin to try breaking
down this code — and fortunately, we don’t have to. That’s what we have
compilers for, right?
Running with the Dynamic Language Runtime
There is more to dynamic languages than just the dynamic typing. You
can do some powerful things. Like all power, you have to be careful not to
misuse it.
The Dynamic Language Runtime — shown in Figure 1-1 — is a library added
to the .NET Framework specifically to provide for adding dynamic languages
(like Ruby) to the Visual Studio fold (like IRONRuby), or to add dynamic lan-
guage features to existing static languages (like C# 4.0).
53_563489-bk08ch01.indd 77653_563489-bk08ch01.indd 776 3/19/10 8:17 PM3/19/10 8:17 PM