/// <summary> /// Evaluate the subexpression with the specified /// parameters. /// </summary> /// <param name="expressionParameterNumber">Parameter number /// corresponding to the subexpression which is to be /// evaluated.</param> /// <param name="parameters">Replacement parameters /// to use for evaluation.</param> /// <returns>The object result of the evaluation</returns> public object EvaluateSubExpression(int expressionParameterNumber, EvaluatorParameters parameters) { MethodInfo methodInfo = this.GetType().GetMethod(string.Format("Eval{0}", expressionParameterNumber), BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic); if (methodInfo == null) { throw new ArgumentException("Could not find a matching evaluation method for that number.", "expressionParameterNumber"); } return(methodInfo.Invoke(this, new object[] { parameters.Parameters })); }
/// <summary> /// Evaluate the expression with the specified /// parameters. /// </summary> /// <param name="parameters">Replacement parameters /// to use for the evaluation.</param> /// <returns>The object result of the evaluation</returns> public abstract object Evaluate(EvaluatorParameters parameters);
/// <summary> /// Evaluate the subexpression with the specified /// parameters. /// </summary> /// <param name="expressionParameterNumber">Parameter number /// corresponding to the subexpression which is to be /// evaluated.</param> /// <param name="parameters">Replacement parameters /// to use for evaluation.</param> /// <returns>The object result of the evaluation</returns> public object EvaluateSubExpression(int expressionParameterNumber, EvaluatorParameters parameters) { MethodInfo methodInfo = this.GetType().GetMethod(string.Format("Eval{0}", expressionParameterNumber), BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic); if (methodInfo == null) { throw new ArgumentException("Could not find a matching evaluation method for that number.", "expressionParameterNumber"); } return methodInfo.Invoke(this, new object[] { parameters.Parameters }); }
private void SetParameters(CodeExpression root, EvaluatorParameters parameters) { if (root is CodeBinaryOperatorExpression) { CodeBinaryOperatorExpression bin = (CodeBinaryOperatorExpression)root; this.SetParameters(bin.Left, parameters); this.SetParameters(bin.Right, parameters); } else { if (root is CodePrimitiveExpression) { CodePrimitiveExpression primitive = (CodePrimitiveExpression)root; int parameterNumber = EvaluatorGenerator.GetParameterIndex(primitive, false); if (parameterNumber >= 0) { parameters.SetParameter(parameterNumber, primitive.Value); } } else { throw new ApplicationException("Cannot evaluate a rule until all variables have been set."); } } }