I have a C # code:
Console.Writeline("Hello World");
If I want to do this with a DLR expression, it looks something like this:
MethodInfo method = typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }); Expression callExpression = Expression.Call(null, method, Expression.Constant("Hello World")); Action callDelegate = Expression.Lambda<Action>(callExpression).Compile(); callDelegate();
I took this example from the Pro DLR book in .NET 4. And I don’t understand why we are doing this extra work? The book says that the reason is that once the code is represented as objects in memory, it is much easier to parse than the IL instruction.
Which confuses me more: If I put the DLR expression instead of the ConsoleWriteline () method in my code and run the console applicator, I get the same .exe file (which contains the CIL code), and as a result I get "Hello world" written on the console . exe executable file. Therefore, in both cases, I get the executable .exe file (cil code) and I don’t see where the objects that represent the code as data at runtime are located , and how can I access them?
source share