|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Linq; |
4 | | -using System.Reflection; |
5 | 4 | using System.Runtime.CompilerServices; |
6 | 5 | using System.Runtime.InteropServices; |
7 | 6 | using System.Threading.Tasks; |
8 | 7 | using ICSharpCode.CodeConverter.Shared; |
9 | 8 | using ICSharpCode.CodeConverter.Util; |
10 | | -using ICSharpCode.CodeConverter.Util.FromRoslyn; |
11 | 9 | using Microsoft.CodeAnalysis; |
12 | 10 | using Microsoft.CodeAnalysis.CSharp; |
13 | 11 | using Microsoft.CodeAnalysis.Editing; |
@@ -273,7 +271,7 @@ public SyntaxToken ConvertIdentifier(SyntaxToken id, bool isAttribute = false, S |
273 | 271 | if (id.SyntaxTree == _semanticModel.SyntaxTree) { |
274 | 272 | var idSymbol = _semanticModel.GetSymbolInfo(id.Parent).Symbol ?? _semanticModel.GetDeclaredSymbol(id.Parent); |
275 | 273 | if (idSymbol != null && !String.IsNullOrWhiteSpace(idSymbol.Name)) { |
276 | | - text = WithDeclarationName(id, idSymbol, text); |
| 274 | + text = WithDeclarationName(id, idSymbol, text, _typeContext.AssembliesBeingConverted); |
277 | 275 | var normalizedText = text.WithHalfWidthLatinCharacters(); |
278 | 276 | if (idSymbol.IsConstructor() && isAttribute) { |
279 | 277 | text = idSymbol.ContainingType.Name; |
@@ -306,10 +304,32 @@ public SyntaxToken ConvertIdentifier(SyntaxToken id, bool isAttribute = false, S |
306 | 304 | /// <seealso cref="DeclarationNodeVisitor.WithDeclarationNameCasingAsync(VBSyntax.NamespaceBlockSyntax, ISymbol)"/> |
307 | 305 | /// <seealso cref="CommonConversions.WithDeclarationNameCasing(TypeSyntax, ITypeSymbol)"/> |
308 | 306 | /// </summary> |
309 | | - private static string WithDeclarationName(SyntaxToken id, ISymbol idSymbol, string text) |
| 307 | + private static string WithDeclarationName(SyntaxToken id, ISymbol idSymbol, string text, IEnumerable<IAssemblySymbol> assembliesBeingConverted) |
310 | 308 | { |
311 | 309 | //This also covers the case when the name is different (in VB you can have method X implements IFoo.Y), but doesn't resolve any resulting name clashes |
312 | | - var baseSymbol = idSymbol.IsKind(SymbolKind.Method) || idSymbol.IsKind(SymbolKind.Property) ? idSymbol.FollowProperty(s => s.BaseMember()).Last() : idSymbol; |
| 310 | + var assemblyIdentities = assembliesBeingConverted.Select(t => t.Identity); |
| 311 | + ISymbol baseSymbol = default; |
| 312 | + var containingType = idSymbol.ContainingType; |
| 313 | + |
| 314 | + if (idSymbol.IsKind(SymbolKind.Method) || idSymbol.IsKind(SymbolKind.Property)) |
| 315 | + { |
| 316 | + var possibleSymbols = idSymbol.FollowProperty(s => s.BaseMember()); |
| 317 | + foreach (var possibleSymbol in possibleSymbols) |
| 318 | + { |
| 319 | + if (!assemblyIdentities.Contains(possibleSymbol.ContainingAssembly.Identity) && possibleSymbol.ContainingType.Equals(containingType)) |
| 320 | + { |
| 321 | + baseSymbol = possibleSymbol; |
| 322 | + break; |
| 323 | + } |
| 324 | + |
| 325 | + baseSymbol = possibleSymbol; |
| 326 | + } |
| 327 | + } |
| 328 | + else |
| 329 | + { |
| 330 | + baseSymbol = idSymbol; |
| 331 | + } |
| 332 | + |
313 | 333 | bool isDeclaration = baseSymbol.Locations.Any(l => l.SourceSpan == id.Span); |
314 | 334 | bool isPartial = baseSymbol.IsPartialClassDefinition() || baseSymbol.IsPartialMethodDefinition() || |
315 | 335 | baseSymbol.IsPartialMethodImplementation(); |
|
0 commit comments