internal static Expression <Func <TResult, bool> > WithParameter <TResult, TSource>(this Expression <Func <TSource, bool> > source, Expression <Func <TResult, TSource> > selector) { // Replace parameter with body of selector var replaceParameter = new ParameterVisitor(source.Parameters, selector.Body); // This will be the new body of the expression var newExpressionBody = replaceParameter.Visit(source.Body); return(Expression.Lambda <Func <TResult, bool> >(newExpressionBody, selector.Parameters)); }
protected internal virtual Query <T> CreateNewQuery(IQuery <T> query, Func <Expression, Expression, Expression> combiner) { var e2 = query.AsExpression(); var newE2 = new ParameterVisitor(e2.Parameters, _expression.Parameters).VisitAndConvert(e2.Body, nameof(CreateNewQuery)); var e3 = combiner(_expression.Body, newE2); var lambda = Expression.Lambda <Func <T, bool> >(e3, _expression.Parameters); return(new Query <T>(lambda)); }