public static IMethodSymbol EnsureNonConflictingNames( this IMethodSymbol method, INamedTypeSymbol containingType, CancellationToken cancellationToken) { // The method's type parameters may conflict with the type parameters in the type // we're generating into. In that case, rename them. var parameterNames = NameGenerator.EnsureUniqueness( method.Parameters.Select(p => p.Name).ToList(), isCaseSensitive: true); var outerTypeParameterNames = containingType.GetAllTypeParameters() .Select(tp => tp.Name) .Concat(method.Name) .Concat(containingType.Name); var unusableNames = parameterNames.Concat(outerTypeParameterNames).ToSet(StringComparer.Ordinal); var newTypeParameterNames = NameGenerator.EnsureUniqueness( method.TypeParameters.Select(tp => tp.Name).ToList(), n => !unusableNames.Contains(n)); var updatedMethod = method.RenameTypeParameters(newTypeParameterNames); return(updatedMethod.RenameParameters(parameterNames)); }