Since the version of Xamarin.iOS 7.2 has basic support for the dynamic C # function. From the release note :
Experimental: Dynamic C # support. We allowed the use of C # dynamics with Xamarin.iOS, but this function is very complicated, 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 successfully compiled and performed dynamic access of anonymous types:
dynamic d = new { name = "x" }; tmp = d.name;
Currently, you need to add the Microsoft.CSharp.dll file as a dependency, otherwise you will 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 JObject are working 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 created two error reports: https://bugzilla.xamarin.com/show_bug.cgi?id=20081 and https://bugzilla.xamarin.com/show_bug.cgi?id=20082 .
source share