private static IEnumerable <(ISymbol Original, string NewName)> GetUniqueNamesForSymbolSet(IEnumerable <ISymbol> symbols) { var membersByCaseInsensitiveName = symbols.ToLookup(SymbolRenamer.GetName, m => m, StringComparer.OrdinalIgnoreCase); var names = new HashSet <string>(membersByCaseInsensitiveName.Select(ms => ms.Key), StringComparer.OrdinalIgnoreCase); var symbolsWithNewNames = membersByCaseInsensitiveName.Where(ms => ms.Count() > 1) .SelectMany(symbolGroup => SymbolRenamer.GetSymbolsWithNewNames(symbolGroup.ToArray(), names, false)); return(symbolsWithNewNames); }
private static IEnumerable <(ISymbol Original, string NewName)> GetUniqueNamesForSymbolSet(IEnumerable <ISymbol> symbols) { #pragma warning disable RS1024 // Compare symbols correctly - analyzer bug, I'm using a string not the default ambiguous comparer var membersByCaseInsensitiveName = symbols.ToLookup(SymbolRenamer.GetName, StringComparer.OrdinalIgnoreCase); #pragma warning restore RS1024 // Compare symbols correctly var names = new HashSet <string>(membersByCaseInsensitiveName.Select(ms => ms.Key), StringComparer.OrdinalIgnoreCase); var symbolsWithNewNames = membersByCaseInsensitiveName.Where(ms => ms.Count() > 1) .SelectMany(symbolGroup => SymbolRenamer.GetSymbolsWithNewNames(symbolGroup.ToArray(), names, false)); return(symbolsWithNewNames); }
private static IEnumerable <(ISymbol Original, string NewName)> GetSymbolsWithNewNames(INamespaceOrTypeSymbol containerSymbol, Compilation compilation) { if (containerSymbol.IsNamespace) { return(Enumerable.Empty <(ISymbol Original, string NewName)>()); } var members = containerSymbol.GetMembers() .Where(m => m.Locations.Any(loc => loc.SourceTree != null && compilation.ContainsSyntaxTree(loc.SourceTree))) .Where(s => containerSymbol.Name == s.Name || containerSymbol is INamedTypeSymbol nt && nt.IsEnumType() && SymbolRenamer.GetName(s).StartsWith(containerSymbol.Name, StringComparison.InvariantCulture)); var symbolSet = containerSymbol.Yield().Concat(members).ToArray(); return(SymbolRenamer.GetSymbolsWithNewNames(symbolSet, new HashSet <string>(symbolSet.Select(SymbolRenamer.GetName)), true)); }