From bd9ee2855236e67d77874ea65cffc88f2d52aa2a Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 24 Aug 2025 12:13:13 +0200 Subject: [PATCH] Fix #1789: missing hyperlink for `MethodGroupResolveResult`. --- ICSharpCode.Decompiler/CSharp/Annotations.cs | 22 ++----------------- ICSharpCode.Decompiler/CSharp/CallBuilder.cs | 4 ++++ .../Resolver/MethodGroupResolveResult.cs | 16 ++++++++++++++ .../Documentation/XmlDocLoader.cs | 8 +++---- .../Output/TextTokenWriter.cs | 4 +++- .../CSharpHighlightingTokenWriter.cs | 6 +++-- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/Annotations.cs b/ICSharpCode.Decompiler/CSharp/Annotations.cs index 30f221db1..c3b2466c8 100644 --- a/ICSharpCode.Decompiler/CSharp/Annotations.cs +++ b/ICSharpCode.Decompiler/CSharp/Annotations.cs @@ -137,27 +137,9 @@ namespace ICSharpCode.Decompiler.CSharp public static ISymbol GetSymbol(this AstNode node) { var rr = node.Annotation(); - if (rr is MethodGroupResolveResult) + if (rr is MethodGroupResolveResult mgrr) { - // delegate construction? - var newObj = node.Annotation(); - if (newObj != null) - { - var funcptr = newObj.Arguments.ElementAtOrDefault(1); - if (funcptr is LdFtn ldftn) - { - return ldftn.Method; - } - else if (funcptr is LdVirtFtn ldVirtFtn) - { - return ldVirtFtn.Method; - } - } - var ldVirtDelegate = node.Annotation(); - if (ldVirtDelegate != null) - { - return ldVirtDelegate.Method; - } + return mgrr.ChosenMethod; } return rr?.GetSymbol(); } diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index e1ee32c3b..6120395d6 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -2025,6 +2025,10 @@ namespace ICSharpCode.Decompiler.CSharp } break; } + if (result is MethodGroupResolveResult mgrr) + { + result = mgrr.WithChosenMethod(method); + } return (currentTarget, addTypeArguments, method.Name, result); } } diff --git a/ICSharpCode.Decompiler/CSharp/Resolver/MethodGroupResolveResult.cs b/ICSharpCode.Decompiler/CSharp/Resolver/MethodGroupResolveResult.cs index d08108c22..2b0463dfe 100644 --- a/ICSharpCode.Decompiler/CSharp/Resolver/MethodGroupResolveResult.cs +++ b/ICSharpCode.Decompiler/CSharp/Resolver/MethodGroupResolveResult.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Net.NetworkInformation; using ICSharpCode.Decompiler.Semantics; using ICSharpCode.Decompiler.TypeSystem; @@ -81,6 +82,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver readonly IReadOnlyList typeArguments; readonly ResolveResult targetResult; readonly string methodName; + IMethod chosenMethod; public MethodGroupResolveResult(ResolveResult targetResult, string methodName, IReadOnlyList methods, IReadOnlyList typeArguments) @@ -148,6 +150,20 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver // the resolver is used to fetch extension methods on demand internal CSharpResolver resolver; + /// + /// Gets the method that was chosen for this group. + /// + /// Only set for MethodGroupResolveResults found in ILSpy AST annotations. + /// + public IMethod ChosenMethod => chosenMethod; + + public MethodGroupResolveResult WithChosenMethod(IMethod method) + { + var result = (MethodGroupResolveResult)ShallowClone(); + result.chosenMethod = method; + return result; + } + /// /// Gets all candidate extension methods. /// Note: this includes candidates that are not eligible due to an inapplicable diff --git a/ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs b/ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs index 3d4c9ce6c..507e3504b 100644 --- a/ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs +++ b/ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs @@ -131,17 +131,17 @@ namespace ICSharpCode.Decompiler.Documentation string localizedXmlDocFile = GetLocalizedName(xmlFileName, currentCulture.Name); string localizedXmlDocFallbackFile = GetLocalizedName(xmlFileName, currentCulture.TwoLetterISOLanguageName); - Debug.WriteLine("Try find XMLDoc @" + localizedXmlDocFile); + //Debug.WriteLine("Try find XMLDoc @" + localizedXmlDocFile); if (File.Exists(localizedXmlDocFile)) { return localizedXmlDocFile; } - Debug.WriteLine("Try find XMLDoc @" + localizedXmlDocFallbackFile); + //Debug.WriteLine("Try find XMLDoc @" + localizedXmlDocFallbackFile); if (File.Exists(localizedXmlDocFallbackFile)) { return localizedXmlDocFallbackFile; } - Debug.WriteLine("Try find XMLDoc @" + xmlFileName); + //Debug.WriteLine("Try find XMLDoc @" + xmlFileName); if (File.Exists(xmlFileName)) { return xmlFileName; @@ -149,7 +149,7 @@ namespace ICSharpCode.Decompiler.Documentation if (currentCulture.TwoLetterISOLanguageName != "en") { string englishXmlDocFile = GetLocalizedName(xmlFileName, "en"); - Debug.WriteLine("Try find XMLDoc @" + englishXmlDocFile); + //Debug.WriteLine("Try find XMLDoc @" + englishXmlDocFile); if (File.Exists(englishXmlDocFile)) { return englishXmlDocFile; diff --git a/ICSharpCode.Decompiler/Output/TextTokenWriter.cs b/ICSharpCode.Decompiler/Output/TextTokenWriter.cs index d225feeaa..a09caf348 100644 --- a/ICSharpCode.Decompiler/Output/TextTokenWriter.cs +++ b/ICSharpCode.Decompiler/Output/TextTokenWriter.cs @@ -118,7 +118,9 @@ namespace ICSharpCode.Decompiler } if (symbol != null && node.Role == Roles.Type && node.Parent is ObjectCreateExpression) { - symbol = node.Parent.GetSymbol(); + var ctorSymbol = node.Parent.GetSymbol(); + if (ctorSymbol != null) + symbol = ctorSymbol; } if (node is IdentifierExpression && node.Role == Roles.TargetExpression && node.Parent is InvocationExpression && symbol is IMember member) diff --git a/ILSpy/Languages/CSharpHighlightingTokenWriter.cs b/ILSpy/Languages/CSharpHighlightingTokenWriter.cs index 2361c8b9a..9b2aa286b 100644 --- a/ILSpy/Languages/CSharpHighlightingTokenWriter.cs +++ b/ILSpy/Languages/CSharpHighlightingTokenWriter.cs @@ -500,9 +500,11 @@ namespace ICSharpCode.ILSpy { symbol = node.Parent.GetSymbol(); } - if (symbol != null && node.Parent is ObjectCreateExpression) + if (symbol != null && node.Role == Roles.Type && node.Parent is ObjectCreateExpression) { - symbol = node.Parent.GetSymbol(); + var ctorSymbol = node.Parent.GetSymbol(); + if (ctorSymbol != null) + symbol = ctorSymbol; } if (node is IdentifierExpression && node.Role == Roles.TargetExpression && node.Parent is InvocationExpression && symbol is IMember member) {