public static Expression <Func <T, bool> > GetExpression <T>(SearchConstraint gridConstraint, ICustomFilterConstraint <T> service)
        {
            Expression <Func <T, bool> > expression = PredicateBuilder.True <T>();

            if (gridConstraint != null)
            {
                foreach (SearchConstraint current in gridConstraint.Groups)
                {
                    if (current != null)
                    {
                        Expression <Func <T, bool> > expression2 = null;
                        foreach (ConstraintRule current2 in current.Rules)
                        {
                            Expression <Func <T, bool> > expression3 = service.CustomFilterExpression(current2);
                            if (expression3 != null)
                            {
                                if (expression2 == null)
                                {
                                    expression2 = expression3;
                                }
                                else
                                {
                                    if (current.GroupOperator.Equals("and", StringComparison.OrdinalIgnoreCase))
                                    {
                                        expression2.And(expression3);
                                    }
                                    else
                                    {
                                        expression2.Or(expression3);
                                    }
                                }
                            }
                        }
                        expression = (gridConstraint.GroupOperator.Equals("and", StringComparison.OrdinalIgnoreCase) ? expression.And(expression2) : expression.Or(expression2));
                    }
                }
            }
            return(expression);
        }
Esempio n. 2
0
        public string GetComplexFilterConstraint(out object[] values, ref Expression <Func <TModel, bool> > expFilterConstraint)
        {
            string text = " 1=1 ";

            values = null;
            if (this.provider is IAutomaticMatchingFilterConstraint <TModel> )
            {
                if (this.Parameters.Where != null)
                {
                    System.Collections.Generic.IList <object> source = new System.Collections.Generic.List <object>();
                    int    num   = 0;
                    string text2 = string.Empty;
                    foreach (SearchConstraint current in this.Parameters.Where.Groups)
                    {
                        bool flag = false;
                        Expression <Func <TModel, bool> > expression = null;
                        if (current != null && current.Rules.Count > 0)
                        {
                            foreach (ConstraintRule current2 in current.Rules)
                            {
                                IAutomaticMatchingFilterConstraint <TModel> automaticMatchingFilterConstraint = this.provider as IAutomaticMatchingFilterConstraint <TModel>;
                                Expression <Func <TModel, bool> >           expression2 = automaticMatchingFilterConstraint.CustomFilterExpression(current2);
                                if (expression2 != null)
                                {
                                    flag = true;
                                    if (expression == null)
                                    {
                                        expression = expression2;
                                    }
                                    else
                                    {
                                        if (current.GroupOperator.Equals("and", System.StringComparison.OrdinalIgnoreCase))
                                        {
                                            expression.And(expression2);
                                        }
                                        else
                                        {
                                            expression.Or(expression2);
                                        }
                                    }
                                }
                            }
                        }
                        if (flag)
                        {
                            if (expFilterConstraint == null)
                            {
                                expFilterConstraint = expression;
                            }
                            else
                            {
                                if (this.Parameters.Where.GroupOperator.Equals("and", System.StringComparison.OrdinalIgnoreCase))
                                {
                                    expFilterConstraint.And(expression);
                                }
                                else
                                {
                                    expFilterConstraint.Or(expression);
                                }
                            }
                        }
                        else
                        {
                            if (current != null && current.Rules.Count > 0)
                            {
                                text2 = text2 + " AND " + SearchConstraintBinder.GetConstraintByAutomaticFilterConstraint <TModel>(current, ref source, ref num);
                            }
                        }
                    }
                    text  += text2;
                    values = source.ToArray <object>();
                }
            }
            else
            {
                if (this.provider is ICustomFilterConstraint <TModel> )
                {
                    ICustomFilterConstraint <TModel> service = this.provider as ICustomFilterConstraint <TModel>;
                    expFilterConstraint = SearchConstraintBinder.GetExpression <TModel>(this.Parameters.Where, service);
                }
                else
                {
                    if (this.Parameters.Where != null)
                    {
                        string text2 = SearchConstraintBinder.GetPredicate <TModel>(this.Parameters.Where, out values);
                        if (!string.IsNullOrEmpty(text2) && text2 != "()")
                        {
                            text = text + " AND " + text2;
                        }
                    }
                }
            }
            return(text);
        }