ILSpy plugin to decompile an assembly with Reflection.Emit API calls
Occasionally I do stuff that's just for fun and has little industrial significance (it's sad how often those two factors seem to correlate...).
One of my hobbies involves diving deep into the .NET framework and creating fun projects. One of these projects were IL-Boss, whose remnants can still be found on Github. The idea was to improve the efficiency of object serialization by generating type-sepcific serialization assemblies at runtime and then reusing them. Kind of like the Json IL serializer but instead of json, I created a compact binary protocoll. This was my bachelor's thesis, I wrote articles about this and it became one of the cornerstones of my, since then interrupted Ph.D. work.
All this was a long time ago; when I first started working on it, Github wasn't cool, Javascript wasn't cool (and to be fair, I'm not sure how cool it is today) and concepts like cloud-first and mobile-first were just about the pop-up.
I'm telling you this so you realize how long I've been usin ILSpy. Because for this project I had to use an IL-decompiler, so that I can get inspiration from somewhere (if I didn't know how to generate a specific piece of code, I wrote it in C# and decompiled it, and then recreated it with the Reflection.Emit API). I'm not even sure if it was open-source back then.
And I'm glad that I've stood by it. Sure, there was a time when development was halted, but for the last couple of years, it's been quite active on Github and they even published a VS extension. Nice.
ILSpy plugins
One cool new feature is that you can write your own plugins. These can be simple things ranging from simple menuitem commands to whole languages.
While looking throught the Github issues of ILSpy I found an interesting one here. The issue is basically a new feature request to create a new decompilation view that instead of the C# code or IL code shows the Reflection.Emit API calls that would be needed to generate that specific piece of code. This is definitely not an easy task, but it I decided to give it a try.
Reflection.Emit decompilation
And today I'm proud to release the first version of my plugin to address the feature request. It's still in the very early stages of development: it only supports methods, and it's riddled with bugs :) But I think it's a decent first try. You can download the release from here, or head over to the Github repository, and then just copy it to the ILSpy directory. Finally, you can choose IL Generation from the language drop-down and behold:
Help wanted
This is a very complex task and I'm not sure how much time I'll have in the near future for this project. If you feel like it, head over to the Github repository, look at the contribution guide and pick a missing feature to implement. Or just help with the testing and create Github issues for bugs and missing features.