コード例 #1
0
ファイル: RuleCompiler.cs プロジェクト: zhlf1987/NRules
        private IRuleFilter CompileFilters(IRuleDefinition ruleDefinition, IList <Declaration> ruleDeclarations)
        {
            var conditions   = new List <IActivationCondition>();
            var keySelectors = new List <IActivationExpression>();

            foreach (var filter in ruleDefinition.FilterGroup.Filters)
            {
                switch (filter.FilterType)
                {
                case FilterType.Predicate:
                    var condition = ExpressionCompiler.CompileFilterCondition(filter, ruleDeclarations);
                    conditions.Add(condition);
                    break;

                case FilterType.KeyChange:
                    var keySelector = ExpressionCompiler.CompileFilterExpression(filter, ruleDeclarations);
                    keySelectors.Add(keySelector);
                    break;

                default:
                    throw new ArgumentOutOfRangeException($"Unrecognized filter type. FilterType={filter.FilterType}");
                }
            }
            var compiledFilter = new RuleFilter(conditions, keySelectors);

            return(compiledFilter);
        }