コード例 #1
0
        public Dictionary <IRule, bool> RunSingleRule(RuleModelData data, string rule)
        {
            if (rule == null)
            {
                return(new Dictionary <IRule, bool>());
            }

            return(Run(data, GetRules(rule)));
        }
コード例 #2
0
        public static void Main()
        {
            var rr    = new RunRules();
            var model = new RuleModelData {
                NumberOfPassengers = 22, NumberOfSeats = 28
            };
            bool result;

            result = rr.RunSingleRule(model, "RelaxedRule").AllParsed(); // obviously RelaxedRule could be loaded in via config or data store
            result = rr.RunSingleRule(model, "GreedRule").AllParsed();   // obviously RelaxedRule could be loaded in via config or data store
            result = rr.Run(model).AllParsed();                          // run all rules

            var allResults = rr.Run(model);
        }
コード例 #3
0
 public bool Parse(RuleModelData data)
 {
     return(data.PercentageFull > PercentHigerThan);
 }
コード例 #4
0
 public Dictionary <IRule, bool> Run(RuleModelData data, IEnumerable <IRule> rules)
 {
     return(rules.Select(f => new { Ob = f, Result = f.Parse(data) })
            .GroupBy(f => f.Ob)
            .ToDictionary(f => f.Key, f => f.Select(x => x.Result).First()));
 }
コード例 #5
0
 public Dictionary <IRule, bool> RunAllWithAppend(RuleModelData data, IEnumerable <IRule> rules)
 {
     return(Run(data, GetRules().Union(rules)));
 }
コード例 #6
0
 public Dictionary <IRule, bool> Run(RuleModelData data)
 {
     return(RunAllWithAppend(data, new IRule[0]));
 }