Ejemplo n.º 1
0
        /// <summary>
        /// Evaluate the current Formula with a passed list of arguments.
        /// </summary>
        /// <param name="arguments">The name/value pairs of arguments.</param>
        /// <returns>An object representing the value of the Formula.</returns>
        public object Evaluate(IDictionary arguments)
        {
            if (resolutionType == FormulaResolutionType.NxBRE)
            {
                if (evaluator == null)
                {
                    evaluator = Compilation.NewEvaluator(expression,
                                                         DEFAULT_EXPRESSION_PLACEHOLDER,
                                                         DEFAULT_NUMERIC_ARGUMENT_PATTERN,
                                                         arguments);
                }
                return(evaluator.Run(arguments));
            }
            else if (resolutionType == FormulaResolutionType.Binder)
            {
                if (formulaSignature == null)
                {
                    formulaSignature = Parameter.BuildFormulaSignature(expression);
                }

                // if arguments have been passed in the formula signature, pass them to the binder as
                // a special entry in the arguments IDictionary (this approach has been preferred to modifying the
                // Compute method signature which would have broken this compatibility
                if (formulaSignature.Arguments.Count > 0)
                {
                    arguments.Add(typeof(Parameter), formulaSignature.Arguments);
                }

                return(bob.Compute(formulaSignature.Name, arguments));
            }
            else
            {
                throw new BREException("Formula evaluation mode not supported: " + resolutionType);
            }
        }