Esempio n. 1
0
 /// <summary>
 /// Instantiates a new Formula predicate.
 /// </summary>
 /// <param name="resolutionType">The type of resolution for the formula.</param>
 /// <param name="bob">The business object binder to use when evaluating the formula, or null.</param>
 /// <param name="expression">The expression value, i.e. the C# code source that should be computable.</param>
 /// <param name="evaluator">A precompiled evaluator, or null.</param>
 private Formula(FormulaResolutionType resolutionType, IBinder bob, string expression, IDictionaryEvaluator evaluator)
     : base(expression)
 {
     this.resolutionType = resolutionType;
     this.bob = bob;
     this.expression = expression;
     this.evaluator = evaluator;
     this.formulaSignature = null;
 }
Esempio n. 2
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);
        }