什么是Expression.Compile做的MonoTouch? [英] What does Expression.Compile do on Monotouch?

查看:185
本文介绍了什么是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.

和它在便携式类库提供

不过通过MonoTouch的.NET运行时的dynamic代码生成不支持

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

由于iPhone的内核防止生成代码动态单开iPhone不支持任何形式的动态代码生成的应用程序。

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.

那么,当你调用Expression.Compile Xamarin的IOS会怎么样?是否抛出和异常,如果有什么异常?并且,随时随地记录?

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选项,它实际上不是在运行时(我不编译知道了发生在后台编译上的细节())。来自微软的文档的例子运行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编译,在这种情况下,你会在运行时得到一个异常有关试图JIT只有AOT选项编译表达式。

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天全站免登陆