Ultimately, the expression tree API is actually just a more familiar API compared to relection.emit, and therefore they are actually equivalent, although I believe there are many things you cannot do in expression trees that you can with using direct reflection.emit.
Reflection.Emit is the fastest overall, but in the same way that the for loop is faster than foreach in general. There are many scenarios in which you can write code that runs faster with reflection.emit than you can use the api expression, but in most cases they should be equivalent.
Now, an API expression does itself a little better than doing things for several reasons.
- This is more complicated than using direct reflection.emit. You can take an expression tree and rewrite it to add some logic much easier than you can using direct IL
- Optimizations may be added in the future that you cannot understand what would not happen when using direction reflection.emit.
So, ultimately, I would say that this is a sink. If this is really important, and you know that reflection is good enough, you can usually use some shortcuts in IL that will not use the expression APIs, but other than that, in general use, they should be fairly equivalent.
source share