public override ResultExpression Invoke(Parameters parameters) { if (Type == ExpressionType.Max) { double max = Children[0].Invoke(parameters).NumberResult; for (int i = 1; i < Children.Count; i++) { max = Math.Max(max, Children[i].Invoke(parameters).NumberResult); } return(Result(max)); } if (Type == ExpressionType.Min) { double min = Children[0].Invoke(parameters).NumberResult; for (int i = 1; i < Children.Count; i++) { min = Math.Min(min, Children[i].Invoke(parameters).NumberResult); } return(Result(min)); } if (Type == ExpressionType.In) { ResultExpression valueInvoke = Children[0].Invoke(parameters); bool isNumModel = valueInvoke.IsNumber(); LinkedList <ResultExpression> invokeResults = new LinkedList <ResultExpression>(); for (int i = 1; i < Children.Count; i++) { ResultExpression invoke = Children[i].Invoke(parameters); if (!(invoke.IsNumber() || invoke.IsNumberList())) { isNumModel = false; } invokeResults.AddLast(invoke); } if (isNumModel) { foreach (var result in invokeResults) { if (result.IsNumber() && ExpressionSetting.Instance.AreEquals(valueInvoke.NumberResult, result.NumberResult)) { return(Result(true)); } if (result.IsNumberList()) { foreach (var res in result.NumberListResult) { if (ExpressionSetting.Instance.AreEquals(valueInvoke.NumberResult, res)) { return(Result(true)); } } } } return(Result(false)); } else { foreach (var result in invokeResults) { if (result.IsList()) { foreach (object res in result.ListResult) { if (valueInvoke.Data.Equals(res)) { return(Result(true)); } } } if (valueInvoke.Data.Equals(result.Data)) { return(Result(true)); } } return(Result(false)); } } if (Type == ExpressionType.Rounding) { var value = Children[0].Invoke(parameters).NumberResult; var digits = Children[1].Invoke(parameters).NumberResult; var result = Math.Round(value, (int)digits, MidpointRounding.AwayFromZero); return(Result(result)); } if (Type == ExpressionType.Ceiling) { ResultExpression invoke = Children[0].Invoke(parameters); double result = invoke.NumberResult; return(Result(Math.Ceiling(result))); } if (Type == ExpressionType.Flooring) { ResultExpression invoke = Children[0].Invoke(parameters); double result = invoke.NumberResult; return(Result(Math.Floor(result))); } if (Type == ExpressionType.Not) { ResultExpression invoke = Children[0].Invoke(parameters); var result = invoke.BooleanResult; return(Result(!result)); } if (Type == ExpressionType.If) { ResultExpression conditionInvoke = Children[0].Invoke(parameters); if (conditionInvoke.BooleanResult) { return(Children[1].Invoke(parameters)); } else { return(Children[2].Invoke(parameters)); } } if (Type == ExpressionType.FunctionAnd) { foreach (var child in Children) { if (!child.Invoke(parameters).BooleanResult) { return(Result(false)); } } return(Result(true)); } if (Type == ExpressionType.FunctionOr) { foreach (var child in Children) { if (child.Invoke(parameters).BooleanResult) { return(Result(true)); } } return(Result(false)); } return(null); }
public override ResultExpression Invoke(Parameters parameters) { if (Type == ExpressionType.Add) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); double result = leftResult.NumberResult + rightResult.NumberResult; return(Result(result)); } if (Type == ExpressionType.Subtract) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); double result = leftResult.NumberResult - rightResult.NumberResult; return(Result(result)); } if (Type == ExpressionType.Multiply) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); double result = leftResult.NumberResult * rightResult.NumberResult; return(Result(result)); } if (Type == ExpressionType.Divide) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); double result = leftResult.NumberResult / rightResult.NumberResult; return(Result(result)); } if (Type == ExpressionType.Greater) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); bool result = leftResult.NumberResult > rightResult.NumberResult; return(Result(result)); } if (Type == ExpressionType.GreaterEqual) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); bool result = leftResult.NumberResult >= rightResult.NumberResult; return(Result(result)); } if (Type == ExpressionType.Less) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); bool result = leftResult.NumberResult < rightResult.NumberResult; return(Result(result)); } if (Type == ExpressionType.LessEqual) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); bool result = leftResult.NumberResult <= rightResult.NumberResult; return(Result(result)); } if (Type == ExpressionType.Equal) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); if (leftResult.IsNumber() && rightResult.IsNumber()) { bool result = ExpressionSetting.Instance.AreEquals(leftResult.NumberResult, rightResult.NumberResult); return(Result(result)); } else if (leftResult.IsNumber() && rightResult.DataType == ResultType.Range) { bool result = RangeUtil.IsInRange(leftResult.NumberResult, rightResult.Data.ToString()); return(Result(result)); } else { bool result = leftResult.Data == rightResult.Data; return(Result(result)); } } if (Type == ExpressionType.NotEqual) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); if (leftResult.IsNumber() && rightResult.IsNumber()) { bool result = !ExpressionSetting.Instance.AreEquals(leftResult.NumberResult, rightResult.NumberResult); return(Result(result)); } else if (leftResult.IsNumber() && rightResult.DataType == ResultType.Range) { bool result = !RangeUtil.IsInRange(leftResult.NumberResult, rightResult.Data.ToString()); return(Result(result)); } else { bool result = leftResult.Data != rightResult.Data; return(Result(result)); } } if (Type == ExpressionType.Power) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); double result = Math.Pow(leftResult.NumberResult, rightResult.NumberResult); return(Result(result)); } if (Type == ExpressionType.Modulo) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); int result = (int)leftResult.NumberResult % (int)rightResult.NumberResult; return(Result(result)); } if (Type == ExpressionType.BooleanAnd) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); bool result = leftResult.BooleanResult && rightResult.BooleanResult; return(Result(result)); } if (Type == ExpressionType.BooleanOr) { ResultExpression leftResult = Left.Invoke(parameters); ResultExpression rightResult = Right.Invoke(parameters); bool result = leftResult.BooleanResult || rightResult.BooleanResult; return(Result(result)); } return(null); }