/// <summary> /// Uses the precedence operator only if needed. i.e. '(' operations ')'. /// <para> - Writes '(' immediately, and returns a disposable that writes the ending ')'.</para> /// <para> - Pushes the operation into the stack, and pops it when disposed.</para> /// </summary> /// <param name="node">The node representing the operation that is going to be rendered inside the using block.</param> /// <returns>Disposable that renders the ending ')' of the precedence operator.</returns> public IDisposable Operation(Expression node) { var op = JsOperationHelper.GetJsOperator(node.NodeType, node.Type); if (op == JavascriptOperationTypes.NoOp) { return(null); } return(new PrecedenceController(this.result, this.operandTypes, op)); }
private bool CurrentHasPrecedence() { var cnt = this.operandTypes.Count; if (cnt < 2) { return(true); } var current = this.operandTypes[cnt - 1]; var parent = this.operandTypes[cnt - 2]; return(JsOperationHelper.CurrentHasPrecedence(current, parent)); }
protected override Expression VisitUnary(UnaryExpression node) { using (this.result.Operation(node)) { var isPostOp = JsOperationHelper.IsPostfixOperator(node.NodeType); if (!isPostOp) { this.result.WriteOperator(node.NodeType); } this.Visit(node.Operand); if (isPostOp) { this.result.WriteOperator(node.NodeType); } return(node); } }
/// <summary> /// Writes the operator that corresponds to the given expression type. /// </summary> /// <param name="expressionType">Expression type representing the operator to render..</param> /// <returns>The <see cref="JavascriptWriter"/>, allowing a fluent style.</returns> public JavascriptWriter WriteOperator(ExpressionType expressionType) { JsOperationHelper.WriteOperator(this.result, expressionType); return(this); }