Exemple #1
0
        public override SyntaxNode VisitParenthesizedExpression(ParenthesizedExpressionSyntax node)
        {
            var newExpression = (ExpressionSyntax)node.Expression.Accept(this);

            // Remove unnecessary parentheses around non-binary expressions
            if (!(newExpression is BinaryExpressionSyntax))
            {
                return(newExpression
                       .WithLeadingTrivia(node.GetLeadingTrivia())
                       .WithTrailingTrivia(node.GetTrailingTrivia()));
            }
            else
            {
                return(node.Expression != newExpression?
                       node.WithExpression(newExpression) : node);
            }
        }
        public override SyntaxNode VisitParenthesizedExpression(ParenthesizedExpressionSyntax node)
        {
            var newExpression = (ExpressionSyntax)node.Expression.Accept(this);

            // Remove unnecessary parentheses around non-binary expressions
            if (!(newExpression is BinaryExpressionSyntax))
            {
                return newExpression
                    .WithLeadingTrivia(node.GetLeadingTrivia())
                    .WithTrailingTrivia(node.GetTrailingTrivia());
            }
            else
            {
                return node.Expression != newExpression ?
                    node.WithExpression(newExpression) : node;
            }
        }
        public override SyntaxNode VisitParenthesizedExpression(ParenthesizedExpressionSyntax node)
        {
            node = node.WithExpression((ExpressionSyntax)base.Visit((SyntaxNode)node.Expression));
            switch (node.Expression.Kind)
            {
                case SyntaxKind.CharacterLiteralExpression:
                case SyntaxKind.FalseLiteralExpression:
                case SyntaxKind.NumericLiteralExpression:
                case SyntaxKind.StringLiteralExpression:
                case SyntaxKind.TrueLiteralExpression:
                    return node.Expression;
            }

            return node;
        }