public static Task <Document> RefactorAsync(
            Document document,
            IfStatementSyntax ifStatement,
            CancellationToken cancellationToken = default)
        {
            IfStatementSyntax newNode = SyntaxRewriter.VisitNode(ifStatement).WithFormatterAnnotation();

            return(document.ReplaceNodeAsync(ifStatement, newNode, cancellationToken));
        }
Esempio n. 2
0
        public static async Task <Document> RefactorAsync(
            Document document,
            IfStatementSyntax ifStatement,
            CancellationToken cancellationToken)
        {
            SyntaxNode oldRoot = await document.GetSyntaxRootAsync(cancellationToken);

            IfStatementSyntax newNode = SyntaxRewriter.VisitNode(ifStatement)
                                        .WithAdditionalAnnotations(Formatter.Annotation);

            SyntaxNode newRoot = oldRoot.ReplaceNode(ifStatement, newNode);

            return(document.WithSyntaxRoot(newRoot));
        }
        public static async Task <Document> RefactorAsync(
            Document document,
            UsingStatementSyntax usingStatement,
            CancellationToken cancellationToken)
        {
            SyntaxNode oldRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            UsingStatementSyntax newNode = SyntaxRewriter.VisitNode(usingStatement)
                                           .WithFormatterAnnotation();

            SyntaxNode newRoot = oldRoot.ReplaceNode(usingStatement, newNode);

            return(document.WithSyntaxRoot(newRoot));
        }
        public static async Task <Document> RefactorAsync(
            Document document,
            ParenthesizedLambdaExpressionSyntax lambda,
            CancellationToken cancellationToken)
        {
            LambdaExpressionSyntax newLambda = SyntaxRewriter.VisitNode(lambda);

            if (lambda.ParameterList.Parameters.Count == 1)
            {
                newLambda = ConvertParenthesizedLambdaToSimpleLambda((ParenthesizedLambdaExpressionSyntax)newLambda);
            }

            newLambda = newLambda.WithFormatterAnnotation();

            return(await document.ReplaceNodeAsync(lambda, newLambda, cancellationToken).ConfigureAwait(false));
        }
Esempio n. 5
0
        public static Task <Document> RefactorAsync(
            Document document,
            IfStatementSyntax ifStatement,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (ifStatement == null)
            {
                throw new ArgumentNullException(nameof(ifStatement));
            }

            IfStatementSyntax newNode = SyntaxRewriter.VisitNode(ifStatement)
                                        .WithFormatterAnnotation();

            return(document.ReplaceNodeAsync(ifStatement, newNode, cancellationToken));
        }
Esempio n. 6
0
        private static async Task <Document> SimplifyLambdaExpressionParameterListAsync(
            Document document,
            ParenthesizedLambdaExpressionSyntax lambda,
            CancellationToken cancellationToken)
        {
            SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            LambdaExpressionSyntax newLambda = SyntaxRewriter.VisitNode(lambda);

            if (lambda.ParameterList.Parameters.Count == 1)
            {
                newLambda = ConvertParenthesizedLambdaToSimpleLambda((ParenthesizedLambdaExpressionSyntax)newLambda);
            }

            newLambda = newLambda.WithFormatterAnnotation();

            root = root.ReplaceNode(lambda, newLambda);

            return(document.WithSyntaxRoot(root));
        }
Esempio n. 7
0
        public static async Task <Document> RefactorAsync(
            Document document,
            IfStatementSyntax ifStatement,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (ifStatement == null)
            {
                throw new ArgumentNullException(nameof(ifStatement));
            }

            SyntaxNode oldRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            IfStatementSyntax newNode = SyntaxRewriter.VisitNode(ifStatement)
                                        .WithFormatterAnnotation();

            SyntaxNode newRoot = oldRoot.ReplaceNode(ifStatement, newNode);

            return(document.WithSyntaxRoot(newRoot));
        }