I work in a code base that is quite large and today I found a project that was emitting IL code
inside a normal class
.
The project containing the IL code being emitted was a implementation of a Service Locator
MSDN Desctiption.
What are the advantages of doing this and why would this be done as apposed to using the C#
language?
Typically this is done to circumvent the overhead of using reflection, using information only available at runtime.
You would then use reflection, which can be slow depending on what you do, to build a new piece of code that works directly with the data given to it, without using reflection.
Advantages:
Disadvantages:
So you need to ensure it's really worth the price before embarking on this.
Note that this is a general answer. In the specific case you came across, there is no way to answer why this was done nor which particular advantages (or disadvantages) you would have without actually seeing the code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With