Ejemplo n.º 1
0
        /// <summary>
        /// Returns the string representation of the statement.
        /// </summary>
        /// <returns>Returns the string representation of the statement.</returns>
        /// <param name="indentation">The number of indented characters.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="indentation"/> is negative.</exception>
        public override string ToString(int indentation)
        {
            if (indentation < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            var ind = new string(' ', indentation);
            var sb  = new StringBuilder();

            sb.Append(ind).Append("if").Append(" ")
            .Append("(").Append(Condition.ToString()).Append(")\n");
            if (TrueStatements != null)
            {
                sb.Append(ind).Append("{\n")
                .Append(TrueStatements.ToString(indentation + 4)).Append("\n")
                .Append(ind).Append("}");
            }
            else
            {
                sb.Append(ind).Append("{ }");
            }
            if (FalseStatements != null)
            {
                sb.Append("\n").Append(ind).Append("else\n")
                .Append(ind).Append("{\n")
                .Append(FalseStatements.ToString(indentation + 4)).Append("\n")
                .Append(ind).Append("}");
            }
            return(sb.ToString());
        }
Ejemplo n.º 2
0
 public CodeConditionStatement(CodeExpression condition,
                               CodeStatement[] trueStatements,
                               CodeStatement[] falseStatements)
 {
     this.condition = condition;
     TrueStatements.AddRange(trueStatements);
     FalseStatements.AddRange(falseStatements);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new object that is a copy of the current instance.
 /// </summary>
 /// <returns>A new object that is a copy of this instance.</returns>
 public override object Clone()
 {
     return(new ConditionStatement(Condition)
     {
         Column = Column,
         Id = Id,
         Line = Line,
         StartOffset = StartOffset,
         NodeLength = NodeLength
     }
            .WithThenBody(TrueStatements.ToArray())
            .WithElseBody(FalseStatements.ToArray()));
 }
Ejemplo n.º 4
0
        protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions)
        {
            generator.WriteBlankLineBeforeEnteringBlock();
            generator.Write(TokenType.Keyword, "if");
            generator.Write(TokenType.Space, ' ');
            generator.Write(TokenType.Punctuation, '(');
            Condition.Generate(generator);
            generator.Write(TokenType.Punctuation, ')');
            if (TrueStatements.Count == 0 && FalseStatements.Count == 0)
            {
                generator.WriteEmptyBlock();
            }
            else
            {
                generator.WriteOpeningBrace();
                generator.Indent++;
                generator.EnterLocalScope();
                TrueStatements.ReserveLocals(generator, default(CodeStatementEmitOptions));
                TrueStatements.Generate(generator, default(CodeStatementEmitOptions));
                generator.ExitLocalScope();
                generator.Indent--;

                if (FalseStatements.Count > 0)
                {
                    generator.WriteMiddleClosingBrace();
                    generator.Write(TokenType.Keyword, "else");
                    generator.WriteOpeningBrace();
                    generator.Indent++;
                    generator.EnterLocalScope();
                    FalseStatements.ReserveLocals(generator, default(CodeStatementEmitOptions));
                    FalseStatements.Generate(generator, default(CodeStatementEmitOptions));
                    generator.ExitLocalScope();
                    generator.Indent--;
                }
                generator.WriteClosingBrace();
            }
        }
Ejemplo n.º 5
0
 /// <devdoc>
 ///    <para>
 ///       Initializes a new instance of <see cref='System.CodeDom.CodeConditionStatement'/>.
 ///    </para>
 /// </devdoc>
 public CodeConditionStatement(CodeExpression condition, params CodeStatement[] trueStatements)
 {
     Condition = condition;
     TrueStatements.AddRange(trueStatements);
 }
 public CodeConditionStatement(ILInstruction inline, CodeExpression condition, CodeStatement[] trueStatements, CodeStatement[] falseStatements) : base(inline)
 {
     Condition = condition;
     TrueStatements.AddRange(trueStatements);
     FalseStatements.AddRange(falseStatements);
 }
Ejemplo n.º 7
0
 public CodeIfStatement(CodeExpression condition, IEnumerable <CodeStatement> trueStatements, IEnumerable <CodeStatement> falseStatements)
 {
     Condition = condition;
     TrueStatements.AddRange(trueStatements);
     FalseStatements.AddRange(falseStatements);
 }