Convert C# code to IL code

malinois picture malinois · Jul 4, 2011 · Viewed 13.5k times · Source

How I can get IL code of C# code ? Can I do this with a extern library, or exists internal functions ?

EDIT : I want to show IL code in my application with a MessageBox.

Answer

Jon Skeet picture Jon Skeet · Jul 4, 2011

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...