System.CodeDom.Compiler.CodeGenerator.GenerateBinaryOperatorExpression C# (CSharp) Method

GenerateBinaryOperatorExpression() protected method

protected GenerateBinaryOperatorExpression ( CodeBinaryOperatorExpression e ) : void
e CodeBinaryOperatorExpression
return void
        protected virtual void GenerateBinaryOperatorExpression(CodeBinaryOperatorExpression e)
        {
            bool indentedExpression = false;
            Output.Write('(');

            GenerateExpression(e.Left);
            Output.Write(' ');

            if (e.Left is CodeBinaryOperatorExpression || e.Right is CodeBinaryOperatorExpression)
            {
                // In case the line gets too long with nested binary operators, we need to output them on
                // different lines. However we want to indent them to maintain readability, but this needs
                // to be done only once;
                if (!_inNestedBinary)
                {
                    indentedExpression = true;
                    _inNestedBinary = true;
                    Indent += 3;
                }
                ContinueOnNewLine("");
            }

            OutputOperator(e.Operator);

            Output.Write(' ');
            GenerateExpression(e.Right);

            Output.Write(')');
            if (indentedExpression)
            {
                Indent -= 3;
                _inNestedBinary = false;
            }
        }

Usage Example

示例#1
0
 public void Visit(CodeBinaryOperatorExpression o)
 {
     g.GenerateBinaryOperatorExpression(o);
 }
CodeGenerator