Lou*_*oux 9 c# lambda delegates expression-trees xamarin.ios
我目前正在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);
Run Code Online (Sandbox Code Playgroud)
这在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)
Run Code Online (Sandbox Code Playgroud)
我做错了什么,我怎么能让它发挥作用?