开发者

A few questions about the DLR

Is it true that all operations on the dynamic type are dispatched to the DLR? From this video, it looks like but they don't say it in so many words and I just want to be sure that the statement is right as I was about to write it in some communication.

They also say that the DLR is currently i开发者_JS百科n System.Core.dll.

I want to know if the DLR has its own assembly or namespace.

I am browsing through the DLR source and it looks like it does have it resides in Microsoft.Scripting.dll but I can't be sure. Did the DLR also ship with .NET 3.5?


Yes, dynamic operations are implemented by the DLR.

The DLR did not ship with .NET 3.5.

The old namespace was for versions of the CLR which did not include the DLR, like 3.5 SP 1. Also for new DLR features not included in .NET 4.


No, the DLR Codeplex source is not what's in the .NET 4.0 framework. Not directly anyway. I'm seeing big chunks of it back in the System.Core.dll assembly, System.Dynamic namespace. To what degree that moved code is identical to the DLR source is hard to guestimate. It looks identical at a cursory glance but you'd need a fine-toothed comb to be sure. The 4.0 source code is available from the Reference Source, just not in a format that makes it easy to run a diff on the source code files. A spot-check on ExpandoClass.cs shows they are very nearly identical with just an added (unnecessary) using directive in the 4.0 version. Given the amount of work done on the DLR previously, I would estimate the changes to be relatively minor.

Note that there is an intermediary layer between the calls generated by the compiler and the DLR. It goes through the classes in the Microsoft.CSharp.dll assembly first, the binder for the C# language. Exactly where that binder ends and the DLR begins is very hard to reverse engineer. The binder code is not easy to read and does a lot of work. Calls to methods in the System.Dynamic namespace are interwoven. And its source code is not available from the Reference Source.

Given the amount of code in the binder, my answer to your question "are all operations on the dynamic type dispatched to the DLR" would be: no, probably not all of them.


When you're using C# with "dynamic", one important player is the C# runtime binder. This component is not part of the DLR, though its functionality depends entirely on the DLR infrastructure. It is located in the assembly Microsoft.CSharp.dll.


I'd recommend to start with MSDN: http://msdn.microsoft.com/en-us/library/dd233052.aspx

Basically, DLR exists in two versions: one ships with .NET 4, another one is open-source version on codeplex.

The DLR in .NET is a part of the System.Core. However, languages and frameworks need their own binders to work with the DLR. In case of C#, this is C# runtime binder, which is in Microsoft.CSharp.dll. So, whatever you declare "dynamic" in C# is first processed by the C# runtime binder and then goes to DLR.

The DLR on codeplex obviously needed its own DLL (which is now Microsoft.Scripting). Basically, DLR started when IronPython guys realized that what they did can be used in more places than just IronPython. So they refactored the code and created a separate DLR layer. This DLR layer was later incorporated into .NET and this is there the two versions forked.

The .NET version is in fact has fewer features than the open-source one. So, if you want to let's say develop your own dynamic langauge on .NET, use the open-source version. If some MS team decides to support dynamic features (like Silverlight did), they usually have to work with the one that is in the .NET Framework.

If you just use C# dynamic features, you basically don't need to worry about DLR at all (the only interesting thing for you might be the System.Dynamic namespace that provides some nice classes such as ExpandoObject and DynamicObject). One more namespace heavily used by DLR (but not strictly a part of it) is System.LINQ.Expressions that is used for operations with expression trees. It was extended for the DLR in this release and you can find it in both the DLR open-source version and .NET Framework.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜