コード例 #1
0
        private static ExpressionSyntax AddParenthesesIfNecessary(SyntaxNode node, ExpressionSyntax expression)
        {
            if (!SyntaxUtility.AreParenthesesRedundantOrInvalid(node))
            {
                expression = expression
                             .WithoutTrivia()
                             .Parenthesize(cutCopyTrivia: true);
            }

            return(expression);
        }
コード例 #2
0
        public static bool CanRefactor(RefactoringContext context, ExpressionSyntax expression)
        {
            if (!SyntaxUtility.AreParenthesesRedundantOrInvalid(expression))
            {
                try
                {
                    Refactor(expression, context.Root);
                    return(true);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    Debug.Assert(false, $"{nameof(WrapExpressionInParenthesesRefactoring)}\r\n{expression.Kind().ToString()}");
                }
            }

            return(false);
        }
コード例 #3
0
        private static async Task <ExpressionSyntax> ReplaceParameterExpressionWithArgumentExpressionAsync(
            ParameterInfo[] parameterInfos,
            InvocationExpressionSyntax invocation,
            ExpressionSyntax expression,
            Solution solution,
            CancellationToken cancellationToken)
        {
            ExpressionSyntax newExpression = await ReplaceParameterExpressionWithArgumentExpressionAsync(parameterInfos, expression, solution, cancellationToken).ConfigureAwait(false);

            if (!SyntaxUtility.AreParenthesesRedundantOrInvalid(invocation))
            {
                newExpression = newExpression
                                .WithoutTrivia()
                                .Parenthesize();
            }

            return(newExpression
                   .WithTriviaFrom(invocation)
                   .WithFormatterAnnotation());
        }