Example #1
0
        public void TestMethod1()
        {
            IDictionary <string, object> src = new Dictionary <string, object>();
            var dest = new List <ExpandoObject>();

            src.Add(new KeyValuePair <string, object>("objectOne", "valueOne"));
            src.Add(new KeyValuePair <string, object>("objectTwo", "valueTwo"));
            src.Add(new KeyValuePair <string, object>("objectThree", "valueThree"));
            src.Add(new KeyValuePair <string, object>("objectFour", "valueFour"));

            var ruleList = new RuleList();
            var ruleOne  = new IncludeRule("!=", "string", "valueZero", true);
            var ruleSet  = new RuleSet();
            var iRules   = new List <IRule> {
                ruleOne
            };

            ruleList.RuleSets.Add(ruleSet);
            var ruleTwo   = new IncludeRule("==", "string", "valueOne", true);
            var ruleThree = new IncludeRule("==", "string", "valueTwo", true);
            var ruleFour  = new IncludeRule("==", "string", "valueThree", true);
            var ruleFive  = new ExcludeRule("==", "string", "valueThree", true);
            var ruleSix   = new ErrorCheckRule("!=", "string", "valueZero", true);


            //ruleList.RuleSets.Add();
            ruleList.Execute(src, ref dest);
        }
        private static List <ExpandoObject> IterateGeneralRules(ref List <ExpandoObject> propertyObject,
                                                                RuleList ruleList,
                                                                ref List <ExpandoObject> destDataRows, ref List <ExpandoObject> errorMessages)
        {
            foreach (var row in propertyObject)
            {
                foreach (var eachRuleSet in ruleList.RuleSets)
                {
                    foreach (var eachBaseRule in eachRuleSet.RuleSets)
                    {
                        if (!(eachBaseRule is IErrorCheck))
                        {
                            eachBaseRule.Configure(row);
                        }
                    }
                }

                try
                {
                    ruleList.Execute(row, ref destDataRows);
                }
                catch (ErrorCheckException ecEx)
                {
                    var ex = new ExpandoObject() as IDictionary <string, object>;
                    ex.Add("ErrorMessage", ecEx.Message);
                    errorMessages.Add((ExpandoObject)ex);
                }
            }

            return(destDataRows);
        }