Writing IL according to the specification

I have to deal with IL quite a bit, whether it’s to write IL code or a C # code that simulates running IL instructions according to C# spec.

In order to write an IL, of course, you need to have a basic knowledge of IL instructions, stack operations, and maybe other certain things.

But there is really no need to write a large method from scratch because you can always write it in C# and see through a decompiler tool how it looks in IL.

So if for example, you need to emit some code (whether with Reflection.Emit or with Cecil, or any other framework), you can write the C# code that emulates the method and then write the decompiled IL.

On the other hand, sometimes the thing is that I do not have to write the IL (because it can be copied from an existing method), but to write code that simulates the execution of the code in the sense of how it will run according to C# spec. (e.g. if you writing an interpreter or asserting generating IL).

Continue reading
Posted in .NET, C#, Internals | Tagged , , , , , , | Leave a comment