Ejemplo n.º 1
0
        public static Expression <Func <TEntity, bool> > Parse <TEntity>(IDataFilter dataFilter, DataFilterMetaInfo filterInfo, Expression node)
        {
            ObjectChecker.CheckNotNull(filterInfo);
            var filterFields = filterInfo.FilterFields;

            if (filterFields.Count == 0)
            {
                return((Expression <Func <TEntity, bool> >)node);
            }

            // filter
            var body = node;

            foreach (var filterField in filterFields)
            {
                var handler = FilterFieldHandlerFactory.GetHandler(filterField.FilterFieldType);
                if (handler != null)
                {
                    // call FilterFieldHandler
                    body = handler.Handle(body, filterField);
                }
            }

            // 删除 {True}
            var optimizer = new ExprTreeOptimizer(body);

            body = optimizer.Optimize();
            return(body as Expression <Func <TEntity, bool> >);
        }
Ejemplo n.º 2
0
        public static Expression <Func <TEntity, bool> > Parse <TEntity>(IDataFilter dataFilter, DataFilterMetaInfo filterInfo, string paramName)
        {
            var body       = Expression.Constant(true, typeof(bool));
            var parameter  = paramName.IsEmpty() ? PredicateBuilder.Paramter <TEntity>() : PredicateBuilder.Paramter <TEntity>(paramName);
            var lambdaExpr = Expression.Lambda <Func <TEntity, bool> >(body, parameter);

            return(Parse <TEntity>(dataFilter, filterInfo, lambdaExpr));
        }