/// <summary>
 /// Initializes a new instance of <see cref="ConditionalStatement" /> for the specified condition, true statement and false statement.
 /// </summary>
 /// <param name="parent">The parent condition in a chain of if-elseif conditions.</param>
 /// <param name="condition">The condition that is tested.</param>
 /// <param name="thenStatement">The statement that is run when the condition evaluates to anything else but falsy.</param>
 /// <param name="elseStatement">The statement that is run when the condition evaluates to falsy.</param>
 public ConditionalStatement(ConditionalStatement parent, Expression condition, Statement thenStatement, Statement elseStatement)
 {
     _parent = parent;
     _condition = condition;
     _thenStatement = thenStatement;
     _elseStatement = elseStatement;
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of <see cref="LoopStatement" /> for the specified initializtion, condition, iteration and statement.
 /// </summary>
 /// <param name="initialization">The initialization of the loop.</param>
 /// <param name="condition">The condition of the loop.</param>
 /// <param name="iteration">The iteration of the loop.</param>
 /// <param name="statement">The statement to run in the loop.</param>
 /// <remarks>
 /// The Statement property cannot be null. Use an <see cref="EmptyStatement"/> statement if necessary.
 /// All of the other parameters are optional, leaving all of them out will result in an eternal loop.
 /// </remarks>
 public LoopStatement(Expression initialization, Expression condition, Expression iteration, Statement statement)
 {
     _initialization = initialization;
     _condition = condition;
     _iteration = iteration;
     _statement = statement;
 }
        /// <summary>
        /// Creates a new instance of <see cref="DoWhileStatement" /> and adds a condition.
        /// </summary>
        /// <param name="whileStatement">The existing instance of <see cref="DoWhileStatement" /> to copy the <see cref="DoWhileStatement.Statement" /> from.</param>
        /// <param name="condition">The condition to add to the new instance.</param>
        /// <returns>a new instance of <see cref="DoWhileStatement" />.</returns>
        public static DoWhileStatement While(this DoWhileStatement whileStatement, Expression condition)
        {
            if (whileStatement == null)
            {
                throw new ArgumentNullException("whileStatement");
            }

            return new DoWhileStatement(condition, whileStatement.Statement);
        }
        /// <summary>
        /// Creates a new instance of the CallOperationExpression class, 
        /// calling on the provided operand with the optionally supplied arguments.
        /// </summary>
        /// <param name="operand">The expression on which to apply the call operation.</param>
        /// <param name="arguments">The arguments to pass in the call.</param>
        public CallOperationExpression(Expression operand, IEnumerable<Expression> arguments)
        {
            _operand = operand;

            if (arguments != null)
            {
                _arguments.AddRange(arguments);
            }
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of <see cref="CaseStatement" />.
        /// </summary>
        /// <param name="value">The literal for which this case is used.</param>
        /// <param name="statements">A sequence of statements that run in this case.</param>
        public CaseStatement(Expression value, IEnumerable<Statement> statements)
        {
            _value = value;

            if (statements != null)
            {
                _statements.AddRange(statements);
            }
        }
        /// <summary>
        /// Creates a new instance of <see cref="IndexOperationExpression" /> that performs an index operation.
        /// </summary>
        /// <param name="expression">An expression to perform an index operation on.</param>
        /// <param name="operand">The index to retrieve.</param>
        /// <returns></returns>
        public static IndexOperationExpression Index(this Expression expression, Expression operand)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            return new IndexOperationExpression(expression, operand);
        }
        /// <summary>
        /// Creates a new instance of <see cref="IteratorStatement" /> that iterates over the specified collection.
        /// </summary>
        /// <param name="statement">The statement to copy the properties from.</param>
        /// <param name="collection">The expression to use as the collection.</param>
        /// <returns>a new instance of <see cref="IteratorStatement" /></returns>
        /// <remarks>
        /// This helper method completes a <see cref="IteratorStatement" />.
        /// It's used as in the following example:
        /// <code>
        /// var iteratorstatement = JS.For(id).In(collection);
        /// </code>
        /// </remarks>
        public static IteratorStatement In(this IteratorStatement statement, Expression collection)
        {
            if (statement == null)
            {
                throw new ArgumentNullException("statement");
            }

            return new IteratorStatement(statement.Variable, collection, statement.Statement);
        }
        /// <summary>
        /// Creates a new instance of <see cref="ConditionalStatement" /> that forms an else-if condition after the specified condition. 
        /// </summary>
        /// <param name="statement">The conditional to which to add an else-if condition to.</param>
        /// <param name="condition">The condition to test.</param>
        /// <returns>a new instance of <see cref="ConditionalStatement" />.</returns>
        /// <remarks>
        /// This produces a new instance, and has no side effects on the existing statement (as all of the helpers are designed to) but
        /// it does refer to the existing instance. Therefore, there may be undesired effects when the original is somehow modified.
        /// However, in the typical use case (a fluent description of the conditional statement) there is no such problem.
        /// </remarks>
        public static ConditionalStatement ElseIf(this ConditionalStatement statement, Expression condition)
        {
            if (statement == null)
            {
                throw new ArgumentNullException("statement");
            }

            ConditionalStatement parent = new ConditionalStatement(statement.Parent, statement.Condition, statement.ThenStatement, null);
            ConditionalStatement result = new ConditionalStatement(parent, condition, null, null);
            parent.ElseStatement = result;

            return result;
        }
        /// <summary>
        /// Creates a new instance of <see cref="ObjectLiteralExpression" />, by copying the specified expression's properties, and adding the specified name and value to the properties.
        /// </summary>
        /// <param name="expression">The expression to copy the properties from.</param>
        /// <param name="name">The name of the property to add.</param>
        /// <param name="value">The value of the property to add.</param>
        /// <returns>a new instance of <see cref="ObjectLiteralExpression" /></returns>
        public static ObjectLiteralExpression WithProperty(this ObjectLiteralExpression expression, Expression name, Expression value)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            ObjectLiteralExpression result = new ObjectLiteralExpression(expression.Properties);

            result.Properties[name] = value;

            return result;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BinaryOperationExpression" /> with the specified operator and operands.
 /// </summary>
 /// <param name="operandLeft">The left side of the binary operation.</param>
 /// <param name="operandRight">The right side of the binary operation.</param>
 /// <param name="op">The binary operator</param>
 public BinaryOperationExpression(Expression operandLeft, Expression operandRight, BinaryOperator op)
 {
     _operandLeft = operandLeft;
     _operandRight = operandRight;
     _operator = op;
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of <see cref="WhileStatement" /> for the specified condition and statement.
 /// </summary>
 /// <param name="condition">The condition to check in the loop.</param>
 /// <param name="statement">The statement to run in the loop.</param>
 public WhileStatement(Expression condition, Statement statement)
 {
     _condition = condition;
     _statement = statement;
 }
 /// <summary>
 /// Initializes a new instance of <see cref="SwitchStatement" /> for the specified expression.
 /// </summary>
 /// <param name="expression">The expression on which to switch.</param>
 public SwitchStatement(Expression expression)
 {
     _expression = expression;
 }
 /// <summary>
 /// Initializes a new instance of <see cref="SwitchStatement" /> for the specified expression and cases.
 /// </summary>
 /// <param name="expression">The expresson on which to switch.</param>
 /// <param name="cases">A sequence of cases.</param>
 public SwitchStatement(Expression expression, IEnumerable<CaseStatement> cases)
 {
     _expression = expression;
     _cases.AddRange(cases);
 }
Example #14
0
 /// <summary>
 /// Creates a new instance of <see cref="UnaryOperationExpression" /> that represents the creation of a new object, using the specified arguments.
 /// </summary>
 /// <param name="expression">An expression that returns a constructor.</param>
 /// <param name="arguments">An array of arguments to pass to the constructor.</param>
 /// <returns>a new instance of <see cref="UnaryOperationExpression" />.</returns>
 public static UnaryOperationExpression New(Expression expression, params Expression[] arguments)
 {
     return new UnaryOperationExpression(new CallOperationExpression(expression, arguments), UnaryOperator.New);
 }
Example #15
0
 /// <summary>
 /// Creates a new instance of <see cref="CallOperationExpression" /> that represents a call to the Microsoft AJAX global '$get' function.
 /// </summary>
 /// <param name="expression">The expression to use an argument to the call.</param>
 /// <returns>a new instance of <see cref="CallOperationExpression" />.</returns>
 public static CallOperationExpression Get(Expression expression)
 {
     return new CallOperationExpression(Id("$get"), expression);
 }
Example #16
0
 /// <summary>
 /// Creates a new instance of <see cref="ThrowStatement" /> that throws the specified expression as an exception.
 /// </summary>
 /// <param name="expression">The expression to throw.</param>
 /// <returns>a new instance of <see cref="ThrowStatement" />.</returns>
 public static ThrowStatement Throw(Expression expression)
 {
     return new ThrowStatement(expression);
 }
 /// <summary>
 /// Initializes a new instance of <see cref="ConditionalStatement" /> for the specified condition, true statement and false statement.
 /// </summary>
 /// <param name="condition">The condition that is tested.</param>
 /// <param name="thenStatement">The statement that is run when the condition evaluates to anything else but falsy.</param>
 /// <param name="elseStatement">The statement that is run when the condition evaluates to falsy.</param>
 public ConditionalStatement(Expression condition, Statement thenStatement, Statement elseStatement)
     : this(null, condition, thenStatement, elseStatement)
 {
 }
Example #18
0
 /// <summary>
 /// Creates a new instance of <see cref="UnaryOperationExpression" /> that surrounds the specified expression with parens.
 /// </summary>
 /// <param name="expression">The expression to surround by parens.</param>
 /// <returns>a new instance of <see cref="UnaryOperationExpression" />.</returns>
 public static UnaryOperationExpression Group(Expression expression)
 {
     return new UnaryOperationExpression(expression, UnaryOperator.Group);
 }
Example #19
0
 /// <summary>
 /// Returns an instance of <see cref="CallOperationExpression" /> containing a call to the alert() function with the specified message.
 /// </summary>
 public static CallOperationExpression Alert(Expression message)
 {
     return new CallOperationExpression(Id("alert"), message);
 }
Example #20
0
 /// <summary>
 /// Returns an instance of <see cref="CallOperationExpression" /> containing a call to the prompt() function with the specified message.
 /// </summary>
 public static CallOperationExpression Prompt(Expression message)
 {
     return new CallOperationExpression(Id("prompt"), message);
 }
Example #21
0
 /// <summary>
 /// Creates a new instance of <see cref="UnaryOperationExpression" /> that performs a logical not operator (!) on an expression.
 /// </summary>
 /// <param name="expression">The expression to perform the logical not operator on.</param>
 /// <returns>A new instance of <see cref="UnaryOperationExpression" /></returns>
 public static Expression Not(Expression expression)
 {
     return new UnaryOperationExpression(expression, UnaryOperator.LogicalNot);
 }
Example #22
0
 public static UnaryOperationExpression New(Expression expression, IEnumerable<Expression> arguments = null)
 {
     return new UnaryOperationExpression(new CallOperationExpression(expression, arguments), UnaryOperator.New);
 }
Example #23
0
 public static LoopStatement For(Expression initialization = null, Expression condition = null, Expression iteration = null)
 {
     return new LoopStatement(initialization, condition, iteration, Empty());
 }
Example #24
0
 /// <summary>
 /// Creates a new instance of <see cref="WhileStatement" /> that will loop while the specified condition returns true.
 /// </summary>
 /// <param name="condition">An expression that the loop will test for.</param>
 /// <returns>a new instance of <see cref="WhileStatement" />.</returns>
 public static WhileStatement While(Expression condition)
 {
     return new WhileStatement(condition, Empty());
 }
 /// <summary>
 /// Creates a new instance of the CallOperationExpression class, 
 /// calling on the provided operand with the optionally supplied arguments.
 /// </summary>
 /// <param name="operand">The expression on which to apply the call operation.</param>
 /// <param name="arguments">The arguments to pass in the call.</param>
 public CallOperationExpression(Expression operand, params Expression[] arguments)
     : this(operand, arguments.AsEnumerable())
 {
 }
Example #26
0
 /// <summary>
 /// Creates a new instance of <see cref="WithStatement" />.
 /// </summary>
 /// <param name="expression">The expression that will be in the global scope.</param>
 /// <returns>a new instance of <see cref="WithStatement" />.</returns>
 public static WithStatement With(Expression expression)
 {
     return new WithStatement(expression, null);
 }
Example #27
0
 public static ReturnStatement Return(Expression value = null)
 {
     return new ReturnStatement(value);
 }
Example #28
0
 /// <summary>
 /// Creates a new instance of <see cref="ConditionalStatement" /> for the specified condition.
 /// </summary>
 /// <param name="condition">The expression that specifies the condition.</param>
 /// <returns>a new instance of <see cref="ConditionalStatement" />.</returns>
 public static ConditionalStatement If(Expression condition)
 {
     return new ConditionalStatement(condition, null, null);
 }
 /// <summary>
 /// Initializes a new instance of <see cref="IteratorStatement" /> for the specified variable, collection and statement.
 /// </summary>
 /// <param name="variable">The variable that holds the item for an iteration.</param>
 /// <param name="collection">The collection on which to iterate.</param>
 /// <param name="statement">The statement to run on each iteration.</param>
 public IteratorStatement(Expression variable, Expression collection, Statement statement)
 {
     Variable = variable;
     Collection = collection;
     Statement = statement;
 }
Example #30
0
 /// <summary>
 /// Creates a new instance of <see cref="SwitchStatement" /> that switches on the provided expression.
 /// </summary>
 /// <param name="expression">An expression to switch on.</param>
 /// <returns>a new instance of <see cref="SwitchStatement" />.</returns>
 public static SwitchStatement Switch(Expression expression)
 {
     return new SwitchStatement(expression);
 }