I've created a lambda expression at runtime, and want to evaluate it - how do I do that? I just want to run the expression by itself, not against any collection or other values.
At this stage, once it's created, I can see that it is of type Expression<Func<bool>>
, with a value of {() => "MyValue".StartsWith("MyV")}
.
I thought at that point I could just call var result = Expression.Invoke(expr, null);
against it, and I'd have my boolean result. But that just returns an InvocationExpression
, which in the debugger looks like {Invoke(() => "MyValue".StartsWith("MyV"))}
.
I'm pretty sure I'm close, but can't figure out how to get my result!
Thanks.