public static Expression <Func <TSource, bool> > BuildSearchExpression(string searchKey, MethodInfo method, Expression <Func <TSource, string> > member, params Expression <Func <TSource, string> >[] others) { var parameter = PagingQueryExtensions.GetParameterExpression(member); var logics = member.ToSearchLambda(method, searchKey) .Or(others.Select(m => m.ToSearchLambda(method, searchKey)).ToArray()); logics = new PagingQueryExtensions.ParameterReplacer(parameter).Visit(logics); var expression = Expression.Lambda <Func <TSource, bool> > (logics, false, parameter); return(expression); }
/// <summary> /// 构造 过滤表达式 /// </summary> /// <returns></returns> public Expression <Func <TSource, bool> > BuildExpression() { if (!expressions.Any()) { return(s => true); } if (expressions.Count == 1) { return(expressions.First()); } var first = expressions.First(); var logics = first.Or(expressions.Skip(1).ToArray()); var parameter = PagingQueryExtensions.GetParameterExpression(first); logics = new PagingQueryExtensions.ParameterReplacer(parameter).Visit(logics); return(Expression.Lambda <Func <TSource, bool> > (logics, false, parameter)); }