Skip to content

Commit bd9ee28

Browse files
committed
Fix #1789: missing hyperlink for MethodGroupResolveResult.
1 parent 587a359 commit bd9ee28

File tree

6 files changed

+33
-27
lines changed

6 files changed

+33
-27
lines changed

ICSharpCode.Decompiler/CSharp/Annotations.cs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,9 @@ internal static TranslatedExpression WithRR(this ExpressionWithILInstruction exp
137137
public static ISymbol GetSymbol(this AstNode node)
138138
{
139139
var rr = node.Annotation<ResolveResult>();
140-
if (rr is MethodGroupResolveResult)
140+
if (rr is MethodGroupResolveResult mgrr)
141141
{
142-
// delegate construction?
143-
var newObj = node.Annotation<NewObj>();
144-
if (newObj != null)
145-
{
146-
var funcptr = newObj.Arguments.ElementAtOrDefault(1);
147-
if (funcptr is LdFtn ldftn)
148-
{
149-
return ldftn.Method;
150-
}
151-
else if (funcptr is LdVirtFtn ldVirtFtn)
152-
{
153-
return ldVirtFtn.Method;
154-
}
155-
}
156-
var ldVirtDelegate = node.Annotation<LdVirtDelegate>();
157-
if (ldVirtDelegate != null)
158-
{
159-
return ldVirtDelegate.Method;
160-
}
142+
return mgrr.ChosenMethod;
161143
}
162144
return rr?.GetSymbol();
163145
}

ICSharpCode.Decompiler/CSharp/CallBuilder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,10 @@ ExpressionWithResolveResult BuildDelegateReference(IMethod method, IMethod invok
20252025
}
20262026
break;
20272027
}
2028+
if (result is MethodGroupResolveResult mgrr)
2029+
{
2030+
result = mgrr.WithChosenMethod(method);
2031+
}
20282032
return (currentTarget, addTypeArguments, method.Name, result);
20292033
}
20302034
}

ICSharpCode.Decompiler/CSharp/Resolver/MethodGroupResolveResult.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Collections.Generic;
2121
using System.Diagnostics;
2222
using System.Linq;
23+
using System.Net.NetworkInformation;
2324

2425
using ICSharpCode.Decompiler.Semantics;
2526
using ICSharpCode.Decompiler.TypeSystem;
@@ -81,6 +82,7 @@ public class MethodGroupResolveResult : ResolveResult
8182
readonly IReadOnlyList<IType> typeArguments;
8283
readonly ResolveResult targetResult;
8384
readonly string methodName;
85+
IMethod chosenMethod;
8486

8587
public MethodGroupResolveResult(ResolveResult targetResult, string methodName,
8688
IReadOnlyList<MethodListWithDeclaringType> methods, IReadOnlyList<IType> typeArguments)
@@ -148,6 +150,20 @@ public IReadOnlyList<IType> TypeArguments {
148150
// the resolver is used to fetch extension methods on demand
149151
internal CSharpResolver resolver;
150152

153+
/// <summary>
154+
/// Gets the method that was chosen for this group.
155+
///
156+
/// Only set for MethodGroupResolveResults found in ILSpy AST annotations.
157+
/// </summary>
158+
public IMethod ChosenMethod => chosenMethod;
159+
160+
public MethodGroupResolveResult WithChosenMethod(IMethod method)
161+
{
162+
var result = (MethodGroupResolveResult)ShallowClone();
163+
result.chosenMethod = method;
164+
return result;
165+
}
166+
151167
/// <summary>
152168
/// Gets all candidate extension methods.
153169
/// Note: this includes candidates that are not eligible due to an inapplicable

ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,25 @@ internal static string LookupLocalizedXmlDoc(string fileName)
131131
string localizedXmlDocFile = GetLocalizedName(xmlFileName, currentCulture.Name);
132132
string localizedXmlDocFallbackFile = GetLocalizedName(xmlFileName, currentCulture.TwoLetterISOLanguageName);
133133

134-
Debug.WriteLine("Try find XMLDoc @" + localizedXmlDocFile);
134+
//Debug.WriteLine("Try find XMLDoc @" + localizedXmlDocFile);
135135
if (File.Exists(localizedXmlDocFile))
136136
{
137137
return localizedXmlDocFile;
138138
}
139-
Debug.WriteLine("Try find XMLDoc @" + localizedXmlDocFallbackFile);
139+
//Debug.WriteLine("Try find XMLDoc @" + localizedXmlDocFallbackFile);
140140
if (File.Exists(localizedXmlDocFallbackFile))
141141
{
142142
return localizedXmlDocFallbackFile;
143143
}
144-
Debug.WriteLine("Try find XMLDoc @" + xmlFileName);
144+
//Debug.WriteLine("Try find XMLDoc @" + xmlFileName);
145145
if (File.Exists(xmlFileName))
146146
{
147147
return xmlFileName;
148148
}
149149
if (currentCulture.TwoLetterISOLanguageName != "en")
150150
{
151151
string englishXmlDocFile = GetLocalizedName(xmlFileName, "en");
152-
Debug.WriteLine("Try find XMLDoc @" + englishXmlDocFile);
152+
//Debug.WriteLine("Try find XMLDoc @" + englishXmlDocFile);
153153
if (File.Exists(englishXmlDocFile))
154154
{
155155
return englishXmlDocFile;

ICSharpCode.Decompiler/Output/TextTokenWriter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ ISymbol GetCurrentMemberReference()
118118
}
119119
if (symbol != null && node.Role == Roles.Type && node.Parent is ObjectCreateExpression)
120120
{
121-
symbol = node.Parent.GetSymbol();
121+
var ctorSymbol = node.Parent.GetSymbol();
122+
if (ctorSymbol != null)
123+
symbol = ctorSymbol;
122124
}
123125

124126
if (node is IdentifierExpression && node.Role == Roles.TargetExpression && node.Parent is InvocationExpression && symbol is IMember member)

ILSpy/Languages/CSharpHighlightingTokenWriter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,11 @@ ISymbol GetCurrentMemberReference()
500500
{
501501
symbol = node.Parent.GetSymbol();
502502
}
503-
if (symbol != null && node.Parent is ObjectCreateExpression)
503+
if (symbol != null && node.Role == Roles.Type && node.Parent is ObjectCreateExpression)
504504
{
505-
symbol = node.Parent.GetSymbol();
505+
var ctorSymbol = node.Parent.GetSymbol();
506+
if (ctorSymbol != null)
507+
symbol = ctorSymbol;
506508
}
507509
if (node is IdentifierExpression && node.Role == Roles.TargetExpression && node.Parent is InvocationExpression && symbol is IMember member)
508510
{

0 commit comments

Comments
 (0)