Expression.Compile在Monotouch上做了什么? [英] What does Expression.Compile do on Monotouch?

查看:127
本文介绍了Expression.Compile在Monotouch上做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以
Expression.Compile 执行以下


将表达式树描述的lambda表达式编译为可执行代码,并生成一个代表lambda表达式的委托。

Compiles the lambda expression described by the expression tree into executable code and produces a delegate that represents the lambda expression.

它在便携式类库中可用。

And it is available in Portable Class Libraries.

然而,当通过Monotouch运行.net 不支持动态代码生成

However when running .net through Monotouch dynamic code generation is not supported


自iPhone的内核阻止应用程序动态生成代码iPhone上的Mono不支持任何形式的动态代码生成。

Since the iPhone's kernel prevents an application from generating code dynamically Mono on the iPhone does not support any form of dynamic code generation.

所以基于那么Xamarin在IOS上不能支持Expression.Compile。

So based on that Xamarin on IOS cannot support Expression.Compile.

那么当你在IOS上调用Expression.Compile Xamarin时会怎么样?是否抛出异常,如果有异常呢?它是否记录在任何地方?

So what happens when you call Expression.Compile Xamarin on IOS ? Does it throw and exception, and if so what exception? And is it documented anywhere?

推荐答案

代码是使用AOT选项编译的,所以实际上不会在运行时编译不知道在Compile())背景中发生的细节。来自Microsoft文档的示例在iOS设备上运行正常,没有例外。

The code is compiled with AOT option so it will actually not be compiled at runtime (I don't know the details that happens in the background on Compile()). The example from Microsoft documentation runs just fine on iOS device, no exceptions.

    public override void FinishedLaunching(UIApplication application)
    {
        System.Linq.Expressions.Expression<Func<int, bool>> expr = i => i < 5;
        // Compile the expression tree into executable code.
        Func<int, bool> deleg = expr.Compile();
        // Invoke the method and print the output.
        Console.WriteLine("deleg(4) = {0}", deleg(4));
    }

您不能在运行时创建IL代码(System.Reflection.Emit),那里也使用反思与某些链接器选项的限制,一些更多的信息在这个线程上。可能有一些表达式没有AOT编译,在这种情况下,您将在运行时遇到一个异常,尝试使用AOT-only选项进行JIT编译。

You cannot create IL code at runtime (System.Reflection.Emit) and there are also restrictions on using Reflection with certain linker options, some more info on this thread. There might be expressions that do not AOT compile and in those cases you would get an exception at runtime about trying to JIT compile with AOT-only option.

这篇关于Expression.Compile在Monotouch上做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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