How Dynamic works in C#
DLR (Dynamic language runtime) is set of services which add dynamic programming capability to CLR. DLR makes dynamic languages like LISP, Javascript, PHP,Ruby to run on .NET framework.
To know more about DLR, please visit
the following link:-
We are going to see how the Dynamics work in .Net now. For example consider the following statement.
dynamic d=GetSomeData(15); When we execute this statement,Let's see what will happen behind the scenes.
When the above statement executes, the DLR will pass the expression trees to the target object.If the dynamic data type is pointing in memory to a COM object, then the expression tree will be sent to the COM interface named IDispatch. This interface is COM's way of incorporating its own set of dynamic services.
If the dynamic data is not pointing to a COM object, then the expression tree may be passed to the object implementing the IDynamicObject interface.This interface is used to map the expression tree to Ruby specifics in the dynamic languages like Iron Ruby.
If suppose the dynamic data is not pointing to COM object and does not implement IDynamicObject, then the object will be considered as .Net object. In this case the expression tree is sent to the C# run time binder for processing.
After the expression tree has been processed by the given binder, the dynamic data will be resolved to the real in-memory data type after which the correct method is called with any necessary parameters.
To know more about the expression tree basics , please read the following article.
http://www.codeproject.com/Articles/235860/Expression-Tree-Basics
No comments:
Post a Comment