Using Linq.Expression<T>
types we can programmatically define AST for later evaluation and/or execution.
But in practical terms, what are the implications of defining the method signature in this way:
public void SomeMethod1(Func<bool> func) { ... } // 1.
instead of
public void SomeMethod2(Expression<Func<bool>> expr) { ... } // 2.
Clearly the way we get the result from Func<bool>
varies from:
var result = func(); // 1.
to
var func = expr.Compile() // 2.
var result = func();
At raw practical level also invocation is similar:
SomeMethod1(() => true); // A.
SomeMethod1(() => AMethodReturnsABool()); // B.
SomeMethod1(AMethodReturnsABool); // C.
with the difference that SomeMethod2
at compile level don't accept the method-group syntax:
//SomeMethod2(AMethodReturnsABool); // -> don't compile
When I need to define a signature with standard delegates Action<T,...>
or Func<T,..>
when I should define them inside an Expression<T>
?