示例#1
0
        //public IDictionary<Rule,string>



        private List <SpecificationInfo <T> > GetSpecificationList(string property)
        {
            // Get These Rules from a database table
            var ta                 = new ProcessingRulesTableAdapter();
            var dataTable          = ta.GetDataByRuleProperty(property);
            var specificationsList = new List <SpecificationInfo <T> >();

            foreach (DataRow dataRow in dataTable.Rows)
            {
                var processingRuleId = Int32.Parse(dataRow["ProcessingRuleId"].ToString());
                var operationName    = dataRow["Operator"].ToString();
                var evalPropertyName = dataRow["EvalProperty"].ToString();
                var value            = dataRow["Value"];
                var mainJoin         = dataRow["MainJoin"].ToString();
                var mainGroup        = int.Parse(dataRow["MainGroup"].ToString());

                var subJoin       = dataRow["SubJoin"]?.ToString() ?? "";
                var subGroupValue = dataRow["SubGroup"]?.ToString() ?? "-1";
                var subGroup      = int.Parse(string.IsNullOrEmpty(subGroupValue) ? "-1" : subGroupValue);

                var ruleValue    = dataRow["RuleValue"].ToString();
                var defaultValue = dataRow["DefaultValue"].ToString();

                Operator operation;
                if (Enum.TryParse(operationName, true, out operation))
                {
                    var rule = new FakeRule(evalPropertyName, operation, value, processingRuleId);

                    var compiledRule = CompileRule <T>(rule);

                    var cplSpec = new FakeRule.ExpressionSpecification <T>(compiledRule);

                    var specificationInfo = new SpecificationInfo <T>();
                    specificationInfo.MainJoin         = mainJoin;
                    specificationInfo.MainGroup        = mainGroup;
                    specificationInfo.SubJoin          = subJoin;
                    specificationInfo.SubGroup         = subGroup;
                    specificationInfo.Specification    = cplSpec;
                    specificationInfo.EvalProperty     = evalPropertyName;
                    specificationInfo.RuleProperty     = property;
                    specificationInfo.RuleValue        = ruleValue;
                    specificationInfo.DefaultValue     = defaultValue;
                    specificationInfo.ProcessingRuleId = processingRuleId;

                    specificationsList.Add(specificationInfo);
                }
            }


            return(specificationsList);


            return(specificationsList);
        }
示例#2
0
        public Func <T, bool> CompileRule <T>(FakeRule rule)
        {
            if (string.IsNullOrEmpty(rule.PropertyName))
            {
                ExpressionBuilder expressionBuilder = new ExpressionBuilder();
                var            param      = Expression.Parameter(typeof(T));
                Expression     expression = expressionBuilder.BuildExpression <T>(rule.Operator_, rule.Value, param);
                Func <T, bool> func       = Expression.Lambda <Func <T, bool> >(expression, param).Compile();

                return(func);
            }
            else
            {
                ExpressionBuilder expressionBuilder = new ExpressionBuilder();
                var            param      = Expression.Parameter(typeof(T));
                Expression     expression = expressionBuilder.BuildExpression <T>(rule.PropertyName, rule.Operator_, rule.Value, param);
                Func <T, bool> func       = Expression.Lambda <Func <T, bool> >(expression, param).Compile();
                return(func);
            }
        }