c# - How do I convert an Expression to a lambda expression? -



c# - How do I convert an Expression to a lambda expression? -

i trying convert look of type expression<func<entity, bool>> func<entity, bool>.

the background here trying mock repository homecoming 1 of collection of mock entities given key value. (i hard code input values mocked method seems wrong approach big number of items).

so trying mock first method on repository this:

var collection = new list<entity> { mockedentity1, mockedentity2, mockedentity3, ... }; mockrepository .setup(rep => rep.first(it.isany<expression<func<entity, bool>>>())) .returns<expression<func<entity, bool>>>(e => collection.first(e));

this doesn't work because collection.first takes func rather expression>. have got point need convert look func contains.

perhaps there simpler or improve this?

you need phone call compile on expression.

c# moq

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -