Only expression trees that represent lambda expressions can be executed. Expression trees that represent lambda expressions are of type LambdaExpression or Expression<(Of <(TDelegate>)>). To execute these expression trees, call the Compile method to create an executable delegate, and then invoke the delegate.
表达式树 只能被包装成 lambdaExpression 对象才能进行计算
一般步骤
- 将表达式树封装在一个LambdaExpression对象
- 调用LambdaExpression的Compile方法动态生成一个委托对象
- 使用DynamicInvoke方法调用该委托对象,获取其返回值
demo