博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Xamarin/Mono IOS Limitations
阅读量:6927 次
发布时间:2019-06-27

本文共 4709 字,大约阅读时间需要 15 分钟。

Since applications on the iPhone using Xamarin.iOS are compiled to static code, it is not possible to use any facilities that require code generation at runtime.

These are the Xamarin.iOS limitations compared to desktop Mono:

 

Limited Generics Support

Unlike traditional Mono/.NET, code on the iPhone is statically compiled ahead of time instead of being compiled on demand by a JIT compiler.

Mono's  technology has a few limitations with respect to generics, these are caused because not every possible generic instantiation can be determined up front at compile time. This is not a problem for regular .NET or Mono runtimes as the code is always compiled at runtime using the Just in Time compiler. But this poses a challenge for a static compiler like Xamarin.iOS.

Some of the common problems that developers run into, include:

Generic Subclasses of NSObjects are limited

Xamarin.iOS currently has limited support for creating generic subclasses of the NSObject class, such as no support for generic methods. As of 7.2.1, using generic subclasses of NSObjects is possible, like this one:

1
2
3
class Foo
: UIView { [..] }

While generic subclasses of NSObjects are possible, there are a few limitations. Read the document for more information

P/Invokes in Generic Types

P/Invokes in generic classes aren't supported:

1
2
3
4
class GenericType
{ [DllImport ("System")] public static extern int getpid (); }

Property.SetInfo on a Nullable Type is not supported

Using Reflection's Property.SetInfo to set the value on a Nullable<T> is not currently supported.

Value types as Dictionary Keys

Using a value type as a Dictionary<TKey, TValue> key is problematic, as the default Dictionary constructor attempts to use EqualityComparer<TKey>.Default. EqualityComparer<TKey>.Default, in turn, attempts to use Reflection to instantiate a new type which implements the IEqualityComparer<TKey> interface.

This works for reference types (as the reflection+create a new type step is skipped), but for value types it crashes and burns rather quickly once you attempt to use it on the device.

Workaround: Manually implement the  interface in a new type and provide an instance of that type to the   constructor.

 

No Dynamic Code Generation

Since the iPhone's kernel prevents an application from generating code dynamically Mono on the iPhone does not support any form of dynamic code generation. These include:

  • The System.Reflection.Emit is not available.
  • No support for System.Runtime.Remoting.
  • No support for creating types dynamically (no Type.GetType ("MyType`1")), although looking up existing types (Type.GetType ("System.String") for example, works just fine).
  • Reverse callbacks must be registered with the runtime at compile time.

     

System.Reflection.Emit

The lack of System.Reflection. Emit means that no code that depends on runtime code generation will work. This includes things like:

  • The Dynamic Language Runtime.
  • Any languages built on top of the Dynamic Language Runtime.
  • Remoting's TransparentProxy or anything else that would cause the runtime to generate code dynamically.

    Important: Do not confuse Reflection.Emit with Reflection. Reflection.Emit is about generating code dynamically and have that code JITed and compiled to native code. Due to the limitations on the iPhone (no JIT compilation) this is not supported.

But the entire Reflection API, including Type.GetType ("someClass"), listing methods, listing properties, fetching attributes and values works just fine.

 

Reverse Callbacks

In standard Mono it is possible to pass C# delegate instances to unmanaged code in lieu of a function pointer. The runtime would typically transform those function pointers into a small thunk that allows unmanaged code to call back into managed code.

In Mono these bridges are implemented by the Just-in-Time compiler. When using the ahead-of-time compiler required by the iPhone there are two important limitations at this point:

  • You must flag all of your callback methods with the 
  • The methods have to be static methods, there is no support for instance methods.

     

No Remoting

The Remoting stack is not available on Xamarin.iOS.

 

Runtime Disabled Features

The following features have been disabled in Mono's iOS Runtime:

  • Profiler
  • Reflection.Emit
  • Reflection.Emit.Save functionality
  • COM bindings
  • The JIT engine
  • Metadata verifier (since there is no JIT)

.NET API Limitations

The .NET API exposed is a subset of the full framework as not everything is available in iOS. See the FAQ for a .

In particular, the API profile used by Xamarin.iOS does not include System.Configuration, so it is not possible to use external XML files to configure the behavior of the runtime.

转载地址:http://vqpjl.baihongyu.com/

你可能感兴趣的文章
oracle客户端服务端字符集-解决乱码
查看>>
Ubuntu部署python3.7的开发和运行环境
查看>>
数据库设计之表名和字段名的设计规范
查看>>
Maven学习总结(18)——深入理解Maven仓库
查看>>
Docker学习总结(4)——Docker镜像与容器命令
查看>>
NTFS格式下的Alternate Data Streams
查看>>
GPIO初始化之PB3/PB4/PA13/PA14/PA15引脚的复用--寄存器版本
查看>>
liunx基础知识
查看>>
VB大全视频30 综合实例企事业人
查看>>
文件时间戳修改touch和查看stat和ls --time
查看>>
基于Easyui的Tree控件做的表达式配置工具
查看>>
thinkphp中 Illegal offset type异常
查看>>
php和表单(1)
查看>>
ajax跨域通信-博客园老牛大讲堂
查看>>
Laravel 项目使用 Carbon 人性化显示文章发表时间
查看>>
自定义Attribute 服务端校验 客户端校验
查看>>
指针作为函数参数返回地址(值)
查看>>
绝对定位
查看>>
论JVM爆炸的几种姿势及自救方法
查看>>
Do NOT hold static session in nhibernate
查看>>