public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { if (!Settings.IsCodeFixEnabled(CodeFixIdentifiers.RemoveTypeParameter)) { return; } SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out TypeParameterSyntax typeParameter)) { return; } foreach (Diagnostic diagnostic in context.Diagnostics) { switch (diagnostic.Id) { case CompilerDiagnosticIdentifiers.TypeParameterHasSameNameAsTypeParameterFromOuterType: { TypeParameterInfo typeParameterInfo = SyntaxInfo.TypeParameterInfo(typeParameter); if (!typeParameterInfo.Success) { break; } CodeAction codeAction = CodeAction.Create( $"Remove type parameter '{typeParameterInfo.Name}'", cancellationToken => { GenericInfo genericInfo = SyntaxInfo.GenericInfo(typeParameterInfo.Declaration); GenericInfo newGenericInfo = genericInfo.RemoveTypeParameter(typeParameter); TypeParameterConstraintClauseSyntax constraintClause = typeParameterInfo.ConstraintClause; if (constraintClause != null) { newGenericInfo = newGenericInfo.RemoveConstraintClause(constraintClause); } return(context.Document.ReplaceNodeAsync(genericInfo.Declaration, newGenericInfo.Declaration, cancellationToken)); }, GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); break; } } } }