Hi there,
I'd like the decompiled C# code emitted by ILSpy to be as close to the original one as possible. In particular, I don't want any code to be deleted. For example, I want the code like
internal sealed class Abc
{
public static void Main()
{
var abc = "string1";
}
}
to be fully restored. As it said in the Architecture Overview, all the optimization is encoded in ILAstOptimization.cs so is performed over the IL AST. I tried to disable it (just commented out the following code):
// ILAstOptimizer bodyGraph = new ILAstOptimizer();
// bodyGraph.Optimize(context, ilMethod);
// context.CancellationToken.ThrowIfCancellationRequested();
in ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(), but unfortunately ended up with invalid C#:
public static void Main()
{
arg_06_0 = "string1";
string abc = arg_06_0;
return;
}
I also found in the Overview mentioned above something about restriction of optimization which might be helpful:
"Dead store removal. If a variable is stored and nobody is there to read it, then was it really written?
Originally
we removed all such dead stores; but after some users complained about 'missing code', we restricted this optimization to apply only to stack
locations. Dead stores to stack locations occur mainly after the removal
of 'pop' instructions."
So could that restriction be unapplied, making the unused automatic variables also appearing in the emitted C# code?
Thank you!