Exemple #1
0
        private TFunc CompileFunction <TFunc>(string formulaText, IList <string> parameters)
            where TFunc : Delegate
        {
            Operation          syntaxTree     = BuildAbstractSyntaxTree(formulaText);
            Expression <TFunc> expressionTree = expressionBuilder.BuildExpressionTree <TFunc>(syntaxTree,
                                                                                              FunctionRegistry,
                                                                                              ConstantRegistry,
                                                                                              parameters);
            TFunc result = expressionTree.Compile();

            return(result);
        }
Exemple #2
0
        public List <ValidationError> Validate <T>(T target, IEnumerable <IValidation> validations, IEnumerable <IValidationCondition> validationConditions)
        {
            List <ValidationError> errors = new List <ValidationError>();

            // Evaluate validation conditions
            foreach (var validation in validations)
            {
                Stack <IToken>     postfixTokens = _postfixConverter.ConvertToStack(validation.Expression);
                ExpressionTreeNode root          = _treeBuilder.BuildExpressionTree(postfixTokens);

                if (EvaluateNode(root, target, validationConditions))
                {
                    errors.Add(new ValidationError()
                    {
                        ErrorMessage = validation.ErrorMessage,
                        ErrorCode    = validation.ErrorCode
                    });
                }
            }

            return(errors);
        }