6

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

1 Answer 1

11

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.