public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); DoStatementSyntax doStatement = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <DoStatementSyntax>(); if (doStatement == null) { return; } CodeAction codeAction = CodeAction.Create( "Use while to create an infinite loop", cancellationToken => { return(ReplaceDoStatementWithWhileStatementRefactoring.RefactorAsync( context.Document, doStatement, cancellationToken)); }, DiagnosticIdentifiers.AvoidUsageOfDoStatementToCreateInfiniteLoop + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out DoStatementSyntax doStatement)) { return; } CodeAction codeAction = CodeAction.Create( "Use while to create an infinite loop", cancellationToken => { return(ReplaceDoStatementWithWhileStatementRefactoring.RefactorAsync( context.Document, doStatement, cancellationToken)); }, GetEquivalenceKey(DiagnosticIdentifiers.AvoidUsageOfDoStatementToCreateInfiniteLoop)); context.RegisterCodeFix(codeAction, context.Diagnostics); }