在 C# .net 中,我们可以使用 .net 动态运行代码System.Codedom.Provider
。同样,有任何可能在 Monotouch (iPhone/iPad) 中动态执行代码。
提前致谢,
在 C# .net 中,我们可以使用 .net 动态运行代码System.Codedom.Provider
。同样,有任何可能在 Monotouch (iPhone/iPad) 中动态执行代码。
提前致谢,
由于 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=20081和https://bugzilla.xamarin.com/show_bug.cgi?id=20082。