Creating expressions as delegates and executing them
We can think of expressions as methods or functions we can call. They might have parameters or not and they might return results or not. We can represent the expressions as either Action or Func. Both are delegate types found in the System namespace. Action represents a parameter-less action that can, if you need to, return results. While Func represents a function that has one or more parameters and can return a result. Both of these delegate types can take generic parameters representing the input parameter types and the result type.
Delegates are basically just representations of methods. They define a callable signature. We can invoke delegates as methods directly.
With expressions, we can turn them into a callable expression. This is done through Expression.Lambda(). Let’s build on the property assign expression we had earlier:
var parameter = Expression.Parameter(typeof(MyType)); var property = typeof(MyType...