コード例 #1
0
 private static void WriteNestedExpression(this IndentedTextWriter writer, int parentPrecedence, BoundExpression expression)
 {
     if (expression is BoundUnaryExpression unary)
     {
         writer.WriteNestedExpression(parentPrecedence, SyntaxFacts.GetUnaryOperatorPrecedence(unary.Op.SyntaxKind), unary);
     }
     else if (expression is BoundBinaryExpression binary)
     {
         writer.WriteNestedExpression(parentPrecedence, SyntaxFacts.GetBinaryOperatorPrecedence(binary.Op.SyntaxKind), binary);
     }
     else
     {
         expression.WriteTo(writer);
     }
 }
コード例 #2
0
        private static void WriteNestedExpression(this IndentedTextWriter writer, int parentPrecedence, int currentPrecedence, BoundExpression expression)
        {
            var needsParenthesis = parentPrecedence >= currentPrecedence;

            if (needsParenthesis)
            {
                writer.WritePunctuation(SyntaxKind.OpenParenthesisToken);
            }

            expression.WriteTo(writer);

            if (needsParenthesis)
            {
                writer.WritePunctuation(SyntaxKind.CloseParenthesisToken);
            }
        }