C# Dynamic Method - IL vs Expression Trees

antlr c# dsl expression-trees il

Question

I'm playing and learning little with ANTLR building a simple DSL for .NET, transforming the script in string into Dynamic Method. My first idea was translate to IL opcodes, but now I am reading about expression trees for DM creation. It seems that I can produce any method using expression trees, just like IL code?

thanks!

Code: https://github.com/ricardoborges/NPortugol2

Popular Answer

IL Code gives you a little more power. For example, you can use it to emit code that's correct for the .NET CLR but not necessarily something you could have written in C# or VB.NET.

But in general yes, you should be able to do just about anything you want to do with expression trees, and they are much simpler to wrap your head around.

Emitting IL code will probably run somewhat faster than compiling an expression tree. I wouldn't worry about this (premature optimization), but it's worth noting. See How does having a dynamic variable affect performance? for some performance specs.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why