I'm looking for a program that will show me the lowest level (ie. no syntactic sugar) C# code given IL code.
I tried using .NET Reflector to view a .exe file that contained a simple console app with a foreach loop, hoping to see GetEnumerator(), MoveNext(), Current etc, however it showed it as a foreach loop.
Does such a program exist? Or is it possible to select "no syntactic sugar" in .NET Reflector?
Current versions of ILSpy have a sizable set of options for enabling/disabling decompiler transformation features:
ICSharpCode.Decompiler.IL.Transforms.*andICSharpCode.Decompiler.CSharp.StatementBuilder; Perhaps open an issue asking, whether a PR for your changes would be appreciated, as most of these "rawness" settings have been added relatively recently.A better example with enumerators
A laconic snippet of code
compiles to
(as seen with all transformation settings disabled)
Further on for-loops:
As far as compilation goes,
for (a; b; c) dis the same asa; while (b) { d; c; }(save for placement of continue-label), so decompilers will take liberty with deciding what kind of loop it might have been based on context similarity between init-statement, condition, and post-statement, so you might even write code by handthat will be detected as a for-loop (for there is no telling in IL)