Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can execute Code Dynamically in monotouch?

In C# .net we can run code dynamically by using System.Codedom.Provider. Like the same is there any possibility to execute the code dynamically in Monotouch (iPhone/iPad).

Thanks in advance,

like image 390
Sri Avatar asked Mar 29 '13 13:03

Sri


2 Answers

Not possible. First because the limitation in how Xamarin.iOS actually works (it doesn't run like a regular .NET apps, but instead compiled to a plain iOS app) and because the security model in Apple Appstore. After all, you can't declare an app to be safe or regulation conforming if the behavior could change anytime.

like image 84
Martheen Avatar answered Oct 18 '22 18:10

Martheen


Since Xamarin.iOS version 7.2 there is some basic support for C#'s dynamic feature. From the release notes:

Experimental: C# dynamic support. We made it possible to use C# dynamic with Xamarin.iOS but the feature is very complex and we need early adopters let us know what dynamic code they run on other platforms or would like to run on Xamarin.iOS.

I've successfully compiled and executed dynamic access of anonymous types:

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

Currently you need to add a Microsoft.CSharp.dll as a dependency -- otherwise you'll get an exception similar to this:

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)

Unfortunately neither ExpandoObject nor Json.Net's JObject work right now:

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

I've created two bug reports for this: https://bugzilla.xamarin.com/show_bug.cgi?id=20081 and https://bugzilla.xamarin.com/show_bug.cgi?id=20082.

like image 33
Rodja Avatar answered Oct 18 '22 16:10

Rodja