public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); ParameterSyntax parameter = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <ParameterSyntax>(); Debug.Assert(parameter != null, $"{nameof(parameter)} is null"); if (parameter == null) { return; } foreach (Diagnostic diagnostic in context.Diagnostics) { switch (diagnostic.Id) { case DiagnosticIdentifiers.AddParameterToDocumentationComment: { var refactoring = new AddParameterToDocumentationCommentRefactoring(); CodeAction codeAction = CodeAction.Create( "Add parameter to documentation comment", cancellationToken => refactoring.RefactorAsync(context.Document, parameter, cancellationToken), diagnostic.Id + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, diagnostic); break; } } } }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out ParameterSyntax parameter)) { return; } foreach (Diagnostic diagnostic in context.Diagnostics) { switch (diagnostic.Id) { case DiagnosticIdentifiers.AddParameterToDocumentationComment: { var refactoring = new AddParameterToDocumentationCommentRefactoring(); CodeAction codeAction = CodeAction.Create( "Add parameter to documentation comment", cancellationToken => refactoring.RefactorAsync(context.Document, parameter, cancellationToken), GetEquivalenceKey(diagnostic)); context.RegisterCodeFix(codeAction, diagnostic); break; } case DiagnosticIdentifiers.OverridingMemberCannotChangeParamsModifier: { if (parameter.IsParams()) { ModifiersCodeFixRegistrator.RemoveModifier(context, diagnostic, parameter, SyntaxKind.ParamsKeyword); } else { ModifiersCodeFixRegistrator.AddModifier(context, diagnostic, parameter, SyntaxKind.ParamsKeyword); } break; } } } }