5

在 C# .net 中,我们可以使用 .net 动态运行代码System.Codedom.Provider。同样,有任何可能在 Monotouch (iPhone/iPad) 中动态执行代码。

提前致谢,

4

2 回答 2

6

不可能。首先是因为 Xamarin.iOS实际工作方式的限制(它不像常规的 .NET 应用程序那样运行,而是编译为普通的 iOS 应用程序),并且因为 Apple Appstore 中的安全模型。毕竟,如果行为随时可能发生变化,您就不能声明应用程序是安全的或符合法规的。

于 2013-03-29T13:48:12.247 回答
6

由于 Xamarin.iOS 版本 7.2 对 C# 的动态功能有一些基本支持。从发行说明

实验性:C# 动态支持。我们使 C# 动态与 Xamarin.iOS 一起使用成为可能,但该功能非常复杂,我们需要早期采用者让我们知道他们在其他平台上运行或希望在 Xamarin.iOS 上运行的动态代码。

我已经成功编译并执行了匿名类型的动态访问:

 dynamic d = new { name = "x" };
 tmp = d.name;

目前,您需要添加 Microsoft.CSharp.dll 作为依赖项 - 否则您将收到类似于此的异常:

Error CS0518: The predefined type `Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported (CS0518) (DynamicSupportOniOS)
Error CS1969: Dynamic operation cannot be compiled without `Microsoft.CSharp.dll' assembly reference (CS1969) (DynamicSupportOniOS)

不幸的是,ExpandoObject 和 Json.Net 的 JObject 现在都不能工作:

dynamic x = new ExpandoObject();
x.NewProp = "demo"; // this still works
Console.WriteLine(x.NewProp); // fails with Xamarin.iOS 7.2

dynamic d = JObject.Parse("{number:1000, str:'string', array: [1,2,3,4,5,6]}");
Console.WriteLine(d.number); // fails with Xamarin.iOS 7.2

我为此创建了两个错误报告:https://bugzilla.xamarin.com/show_bug.cgi?id=20081https://bugzilla.xamarin.com/show_bug.cgi?id=20082

于 2014-05-28T08:17:27.923 回答