Is there a tool for MSIL results

I am very interested in the work of MSIL. As I understand it, at compile time, the CLR translates its code into MSIL to provide some optimizations that JIT later translates into machine code.

For example, if we have:

using (TextWriter w = File.CreateText("log.txt")) { w.WriteLine("This is line one"); } 

it will be converted to MSIL with the following code:

  TextWriter w = File.CreateText("log.txt"); try { w.WriteLine("This is line one"); } finally { bool flag = w == null; if (!flag) { w.Dispose(); } } 

I am not sure that it will be translated exactly like that, but definitely to something like that.

The thing is, I'm trying to research the MSIL optimization. Until that moment, I found that MSIL was translated into asm code, which is not readable for me.

Is there any tool that shows that I have translated MSIL into C # code or even pseudo code?

Appreciate links and links to them.

PS

I wrote using the above:

  using (TextWriter w = File.CreateText("log.txt")) { w.WriteLine("This is line one"); } 

and compiled it. Then I used Reflector to see the code, and I saw the same code that I wrote instead to see some optimizations.

I used LINQPad with the same code. I found that the output of MSIL is:

  IL_0001: ldstr "log.txt" IL_0006: call System.IO.File.CreateText IL_000B: stloc.0 // w IL_000C: nop IL_000D: ldloc.0 // w IL_000E: ldstr "This is line one" IL_0013: callvirt System.IO.TextWriter.WriteLine IL_0018: nop IL_0019: nop IL_001A: leave.s IL_002C IL_001C: ldloc.0 // w IL_001D: ldnull IL_001E: ceq IL_0020: stloc.1 // CS$4$0000 IL_0021: ldloc.1 // CS$4$0000 IL_0022: brtrue.s IL_002B IL_0024: ldloc.0 // w IL_0025: callvirt System.IDisposable.Dispose IL_002A: nop IL_002B: endfinally 

From this code, we see System.IDisposable.Dispose, which looks like part of the optimization. My intention is to somehow see the C # code or pseudocode.

+4
source share
4 answers

I would recommend Telerik JustDecompile. It will be Free Forever.

Historically for a long time Lutz was the "Reflector" Raeder. But now it belongs to RedGate. You can still get it for a healthy price.

+1
source

Reflector , ILSpy , dotPeek, and ildasm .

Reflexil is a pretty nice plugin for Reflector. But as it was written, Reflector is now paid.

About optimization:

Is there something to optimize? Have you checked the "Optimize code" in the project properties? The JIT compiler also performs some compilation optimizations. You can get the machine code of your method using the SOS extensions:

Get JIT Report

How to see what JIT compiles?

Debugging with SOS, SOSEX and dumps in Visual Studio

+1
source

I recommend IlSpy, it's free and reliable

http://ilspy.net/

0
source

ILSpy (http://ilspy.net/) is good and free, and you can check the source code if you want. The reflector is good, but not free (avec expensive).

0
source

All Articles