tags:

views:

655

answers:

1

I have a this line of code:

var predicate = Expression.Lambda<Func<TEntityType, bool>>(body, param);

where TEntityType is a generic parm.

However, I don't have generic parm available. I do have:

Type _EntityType;

What is the non-generic syntax for Expression.Lambda is this case?

Thanks

+5  A: 

There's an overload for Expression.Lambda that takes the type of the expression body, so you just need to create the type dynamically before calling that overload.

type lambdaType = typeof(Func<,>).MakeGenericType(_EntityType, typeof(bool));

var predicate = Expression.Lambda(lambdaType, body, param);
Cameron MacFarland
Ok... Thankss. The compiler accepts this syntax.
theBruce
Thanks very helpful.
Graphain