public override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out ThrowStatementSyntax throwStatement)) { return; } CodeAction codeAction = CodeAction.Create( "Remove original exception from throw statement", cancellationToken => RemoveOriginalExceptionFromThrowStatementRefactoring.RefactorAsync(context.Document, throwStatement, cancellationToken), GetEquivalenceKey(DiagnosticIdentifiers.RemoveOriginalExceptionFromThrowStatement)); context.RegisterCodeFix(codeAction, context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); ThrowStatementSyntax throwStatement = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <ThrowStatementSyntax>(); if (throwStatement == null) { return; } CodeAction codeAction = CodeAction.Create( "Remove original exception from throw statement", cancellationToken => RemoveOriginalExceptionFromThrowStatementRefactoring.RefactorAsync(context.Document, throwStatement, cancellationToken), DiagnosticIdentifiers.RemoveOriginalExceptionFromThrowStatement + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }