MonoTouch and supporting variant generic interfaces

我们两清 提交于 2020-01-01 09:53:09

问题


The below example compiles fine in regular Mono 2.10.9:

namespace covarianttest
{
    public interface ITest<out T> : IEnumerable<T>
    {
    }
}

However when I attempt compile it against MonoTouch 6.0.8 I receive this error:

Error CS1961: The covariant type parameter 'T' must be invariantly valid on 'covarianttest.ITest'

So am I to assume that MonoTouch doesn't support extending covariant/contravariant generic interfaces yet? If so what is the recommend workaround for this situation in MonoTouch?


回答1:


This actually depend on the compiler (and profile/runtime) not the Mono version. IOW some things might work on Mono 2.10 and not with MonoTouch 6.x.

Current versions of MonoTouch ships with the smcs compiler and a 2.1 based profile (mostly Silverlight and some .NET 4.0 additions).

Newer features, like covariance, requires a full 4.0 compiler (e.g. dmcs in Mono 2.10 or mcs in Mono 3.0) and runtime.

Future versions of MonoTouch (likely this spring with alpha/beta in early 2013) will provide a 4.0/4.5 runtime and compiler.



来源:https://stackoverflow.com/questions/14093332/monotouch-and-supporting-variant-generic-interfaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!