views:

26

answers:

1

I looked through PredicateBuilder sources and its' implementation makes me curious. Let's look at Or method implementation:

public static Expression<Func<T, bool>> Or<T> (this Expression<Func<T, bool>> expr1,
                                                      Expression<Func<T, bool>> expr2)
  {
    var invokedExpr = Expression.Invoke (expr2, expr1.Parameters.Cast<Expression> ());
    return Expression.Lambda<Func<T, bool>>
          (Expression.OrElse (expr1.Body, invokedExpr), expr1.Parameters);
  }

Why does it Invoke new lambda instead of just using OrElse for predicate body?

+2  A: 

I believe it's a typing issue: Expression.OrElse returns a plain Expression, not an Expression<Func<T, bool>>.

Rafe
Good point, may be it is just a workaround to get rid off expression type casting (to be able to access to Body property). But it makes expression more difficult...
Idsa