/// <summary> /// Compiles equations between left and right and based on Operation specified, determines the mathematical binary expression and sends the output back to caller. /// </summary> /// <param name="oper">Comparison Operation (APIConditionOperator)</param> /// <returns></returns> private bool CompareOperands(APIConditionOperator oper) { Expression <Func <string, string, bool> > expression = null; switch (oper) { case APIConditionOperator.EQ: expression = (left, right) => left.Equals(right); break; case APIConditionOperator.NE: expression = (left, right) => !left.Equals(right); break; case APIConditionOperator.GT: expression = (left, right) => left.ToDouble() > right.ToDouble(); break; case APIConditionOperator.LT: expression = (left, right) => left.ToDouble() < right.ToDouble(); break; case APIConditionOperator.GE: expression = (left, right) => left.ToDouble() >= right.ToDouble(); break; case APIConditionOperator.LE: expression = (left, right) => left.ToDouble() <= right.ToDouble(); break; } if (expression != null) { var delegateOperation = expression.Compile(); var res = delegateOperation(Left, Right); return(res); } else { return(false); } }
/// <summary> /// Constructor. /// </summary> /// <param name="objects">Objects to get equation place holder values.</param> /// <param name="operand">Template mathematical equation for left side operand</param> /// <param name="oper">Comparison operation as of now.</param> /// <param name="comparer">Template mathematical equation for right side operand</param> internal APIExpression(List <object> objects, string operand, APIConditionOperator oper, string comparer) { Objects = objects; Operand = operand; Operator = oper; Comparer = comparer; }