score:8

Accepted answer
Expression<Func<T, bool>> falsePredicate = x => false;

score:6

Can you wrap the entire thing in an if-else expression?

Meaning:

if input
    return <your normal code>
else
    return false

The return is implicit in expressions; the return value of the expression will simply be the last value. So you could try:

    Expression.Condition
    (
      Expression.NotEqual(input, Expression.Constant("")), 
      normalSearchExpression, 
      Expression.Constant(false)
    )

That's assuming normalSearchExpression also returns a bool.


Related Articles