private void AnalyzeDoStatement(SyntaxNodeAnalysisContext context) { var doStatement = (DoStatementSyntax)context.Node; if (ReplaceDoWithWhileRefactoring.CanRefactor(doStatement)) { context.ReportDiagnostic( DiagnosticDescriptors.AvoidUsageOfDoStatementToCreateInfiniteLoop, doStatement.DoKeyword); } AddEmptyLineAfterLastStatementInDoStatementRefactoring.Analyze(context, doStatement); }
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(ReplaceDoWithWhileRefactoring.RefactorAsync( context.Document, doStatement, cancellationToken)); }, GetEquivalenceKey(DiagnosticIdentifiers.AvoidUsageOfDoStatementToCreateInfiniteLoop)); context.RegisterCodeFix(codeAction, context.Diagnostics); }