Exemple #1
0
 private async Task <Document> InvertForAsync(Document document, ForStatementSyntax @for, CancellationToken cancellationToken)
 {
     if (InvertForAnalyzer.IsPostIncrement(@for.Incrementors[0]))
     {
         return(await ConvertToDecrementingCounterForLoopAsync(document, @for, cancellationToken));
     }
     return(await ConvertToIncrementingCounterForLoopAsync(document, @for, cancellationToken));
 }
Exemple #2
0
        static SeparatedSyntaxList <ExpressionSyntax> ToggleIncrement(ForStatementSyntax @for)
        {
            var incrementor    = (PostfixUnaryExpressionSyntax)@for.Incrementors[0];
            var newIncrementor = SyntaxFactory.PostfixUnaryExpression(
                InvertForAnalyzer.IsPostIncrement(incrementor) ? SyntaxKind.PostDecrementExpression : SyntaxKind.PostIncrementExpression,
                incrementor.Operand);

            return(new SeparatedSyntaxList <ExpressionSyntax>().Add(newIncrementor));
        }
Exemple #3
0
        private async static Task <Document> InvertForAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
        {
            var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            var diagnosticSpan = diagnostic.Location.SourceSpan;
            var @for           = root.FindToken(diagnosticSpan.Start).Parent.AncestorsAndSelf().OfType <ForStatementSyntax>().First();

            if (InvertForAnalyzer.IsPostIncrement(@for.Incrementors[0]))
            {
                return(await ConvertToDecrementingCounterForLoopAsync(document, @for, cancellationToken));
            }
            return(await ConvertToIncrementingCounterForLoopAsync(document, @for, cancellationToken));
        }