为什么LambdaExpression.Compile()在iOS(Xamarin)上可以使用? [英] Why does LambdaExpression.Compile() work on iOS (Xamarin)?

查看:87
本文介绍了为什么LambdaExpression.Compile()在iOS(Xamarin)上可以使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Xamarin.iOS在运行时不支持代码生成,为什么Compile()和DynamicInvoke()可以按预期工作?

Since Xamarin.iOS doesn't support code generation at runtime, why do Compile() and DynamicInvoke() work as expected?

例如,以下代码可以正常工作:

For example, the following code works fine:

var lambda = Expression.Lambda(
                          Expression.Add(
                              Expression.Constant(1),
                              Expression.Constant(2)
                          )
             );

var f = lambda.Compile();
var result = f.DynamicInvoke();

// result==3 at this point

Xamarin是否正在评估

Is Xamarin evaluating the expression tree at runtime instead of emitting IL code?

推荐答案

在支持代码生成的平台上,基于Reflection.Emit的 LambdaCompiler

On platforms that support code generation, Reflection.Emit-based LambdaCompiler is used.

如果不可用,则使用解释器。例如,有些类解释 常量 添加

If that's not available, the expression is interpreted using the interpreter. For example, there are classes that interpret Constant and Add.

这篇关于为什么LambdaExpression.Compile()在iOS(Xamarin)上可以使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆