Is it possible to create a method which returns a lambda expression? I couldn’t find any proper examples.
The following syntax doesn’t work, of course. It’s just to visualize my idea a bit:
// Executed code
var filteredList = listWithNames.Where(GetLambdaExpression("Adam"));
// method
public Expression GetLambdaExpression(string name)
{
return listElement => listElement.Name == name;
}
You can create functions which return expressions such as this as a simple example in a predicate builder:
or this expression builder:
in your example case You should use what Leppie has mentioned below (which I have upvoted)