示例#1
0
        /// <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 }));
        }
示例#2
0
 /// <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);
示例#3
0
        /// <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 });
        }
示例#4
0
 /// <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);
示例#5
0
        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.");
                }
            }
        }