Convert C# code to IL code
How I can get IL code of C# code ? Can I do this with a extern li开发者_开发问答brary, or exists internal functions ?
EDIT : I want to show IL code in my application with a MessageBox.Programmatically? You can use reflection to get a MethodInfo
, and then call MethodBase.GetMethodBody
to get the body. From the MethodBody
, you can call GetILAsByteArray
amongst other things.
Of course, if you just want to examine it yourself, there's Reflector, dotPeek, ildasm (part of the .NET SDK) and no doubt other tools...
Use IL Disassembler like this:
c:\il>csc Class.cs
c:\il>ildasm /output=Class.il Class.exe
you'll both have the IL & the exe.
Just open a Visual Studio command prompt and type ildasm - with ildasm you can open up any assembly and show the generated IL.
Take a look at LinqPad, it has options to see IL.
OR,
Start -> Programs -> Microsoft .NET Framework SDK (Version) -> Tools -> MSIL Disassembler
It's quite an old question, but I'd like to add some accuracies.
GetMethodBody()
will give you at best a byte array, which you need to parse manually (which can be painful since some opcodes have two bytes) to get a human readable text.
I just want to mention ILSpy as an alternate solution.
It's open source, meaning you can debug it and integrate with it in your solution.
精彩评论