public Specification <T> AndAlso(Expression <Func <T, bool> > andWhere) { if (Where == null) { Where = andWhere; return(this); } var p = Where.Parameters[0]; var visitor = new SubstExpressionVisitor { Subst = { [andWhere.Parameters[0]] = p } }; Expression body = Expression.AndAlso(Where.Body, visitor.Visit(andWhere.Body) ?? throw new InvalidOperationException()); Where = Expression.Lambda <Func <T, bool> >(body, p); return(this); }
public Specification <T> OrElse(Expression <Func <T, bool> > orWhere) { //TODO Refactor if (Where == null) { Where = orWhere; return(this); } var p = Where.Parameters[0]; var visitor = new SubstExpressionVisitor { Subst = { [orWhere.Parameters[0]] = p } }; Expression body = Expression.OrElse(Where.Body, visitor.Visit(orWhere.Body) ?? throw new InvalidOperationException()); Where = Expression.Lambda <Func <T, bool> >(body, p); return(this); }