【发布时间】:2011-07-22 22:10:27
【问题描述】:
我目前正在MonoTouch 中移植一个.NET 代码库,并且我目前正在研究一种接收Expression<T> 的方法。我正在尝试编译它,然后动态调用它。
这就是我所做的:
// Here's an example of what I could receive
Expression<Action<int>> expression = (a => Console.WriteLine (a * 2));
// And here's what I'm trying to do to invoke it
expression.Compile().DynamicInvoke(6);
这在 iOS 模拟器中运行良好,结果“12”打印在我的控制台中。但后来我在 iPad 上试了一下,收到如下异常。
Object reference not set to an instance of an object
at System.Linq.jvm.Runner.CreateDelegate ()
at System.Linq.Expressions.LambdaExpression.Compile ()
at System.Linq.Expressions.Expression`1[System.Action`1[System.Int32]].Compile ()
at TestSolution2.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options)
我做错了什么,我该如何让它发挥作用?
【问题讨论】:
标签: c# delegates lambda xamarin.ios expression-trees