diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/OverloadResolution.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/OverloadResolution.cs index 50925bddd..3ad1aab79 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/OverloadResolution.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/OverloadResolution.cs @@ -42,6 +42,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness #endif Issue2444.M2(); Issue2741.B.Test(new Issue2741.C()); + ExtensionMethodDemo.Issue2165.Test(); } #region ConstructorTest @@ -550,3 +551,46 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness } } } + +namespace ExtensionMethodDemo +{ + // First extension class with an out int parameter + public static class StringExtensions + { + public static bool TryParseCustom(this string input, out int result) + { + return int.TryParse(input, out result); + } + } + + // Second extension class with an out double parameter + public static class StringDoubleExtensions + { + public static bool TryParseCustom(this string input, out double result) + { + return double.TryParse(input, out result); + } + } + + class Issue2165 + { + public static void Test() + { + string value1 = "123"; + string value2 = "123.45"; +#if CS70 + // Use the int version with extension method syntax + if (value1.TryParseCustom(out int intResult)) + { + Console.WriteLine("Parsed int: " + intResult); + } + + // Use the double version with extension method syntax + if (value2.TryParseCustom(out double doubleResult)) + { + Console.WriteLine("Parsed double: " + doubleResult); + } +#endif + } + } +} diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs b/ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs index c84d9e81a..720f8d900 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs @@ -622,13 +622,16 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms { // 'T v; SomeCall(out v);' can be combined to 'SomeCall(out T v);' AstType type; + bool isOutVar = false; if (context.Settings.AnonymousTypes && v.Type.ContainsAnonymousType()) { type = new SimpleType("var"); + isOutVar = true; } else if (dirExpr.Annotation() != null) { type = new SimpleType("var"); + isOutVar = true; } else { @@ -652,6 +655,11 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms var ovd = new OutVarDeclarationExpression(type, name); ovd.Variable.AddAnnotation(new ILVariableResolveResult(ilVariable)); ovd.CopyAnnotationsFrom(dirExpr); + if (isOutVar) + { + ovd.RemoveAnnotations(); + ovd.AddAnnotation(new OutVarResolveResult(v.Type)); + } replacements.Add((dirExpr, ovd)); } else