In my interface I have following defined
List<IFoo> GetListOfFoo<T>(Expression<Func<T, bool>> predicate) where T : IFoo;
In my implementation I'll cast the expression in the specific type:
if (typeof(T) == typeof(Foo))
{
Expression converted = Expression.Convert(predicate.Body, typeof(Foo));
Expression<Func<Foo, bool>> newPredicate =
Expression.Lambda<Func<Foo, bool>>(converted, predicate.Parameters);
}
I try to use my implementation like this:
Expression<Func<Foo, bool>> predicate = c => c.Name == "Myname";
_repository.GetListOfFoo<Foo>(predicate);
I get no compiling errors, but if I use this, I get an Exception that in the ExpressionBody is the bool argument defined.
Where is my problem?