Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DecompilerSettings.ExtensionMethods = false; Dosen't work #3355

Closed
naratteu opened this issue Jan 1, 2025 · 0 comments
Closed

DecompilerSettings.ExtensionMethods = false; Dosen't work #3355

naratteu opened this issue Jan 1, 2025 · 0 comments
Labels
Bug Decompiler The decompiler engine itself

Comments

@naratteu
Copy link
Contributor

naratteu commented Jan 1, 2025

Input code

Add-Type -TypeDefinition @"
public static class HelloWorld
{
    public static void Main() => "Hello World!".Say();
    static void Say(this string msg) => System.Console.WriteLine("Hello, World!");
}
"@ -OutputAssembly "HelloWorld.dll"
#r "nuget: ICSharpCode.Decompiler, 9.0.0.7833-preview3"
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp;
DecompilerSettings s = new(){ ExtensionMethods = false };
var dll = "HelloWorld.dll";
return new CSharpDecompiler(dll, s).DecompileWholeModuleAsString();

Erroneous output

using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
public static class HelloWorld
{
	public static void Main()
	{
		"Hello World!".Say();
	}

	private static void Say(this string msg)
	{
		Console.WriteLine("Hello, World!");
	}
}

Correct output

#3356
this above commit solved it.

using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: Extension]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
[Extension]
public static class HelloWorld
{
	public static void Main()
	{
		Say("Hello World!");
	}

	[Extension]
	private static void Say(string msg)
	{
		Console.WriteLine("Hello, World!");
	}
}
@naratteu naratteu added Bug Decompiler The decompiler engine itself labels Jan 1, 2025
siegfriedpammer added a commit that referenced this issue Jan 2, 2025
Fix #3355 : Insert missing DecompilerSettings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Decompiler The decompiler engine itself
Projects
None yet
Development

No branches or pull requests

1 participant