Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MonoTouch and supporting variant generic interfaces

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?

like image 682
Rodney S. Foley Avatar asked Dec 30 '12 18:12

Rodney S. Foley


1 Answers

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.

like image 125
poupou Avatar answered Nov 26 '22 13:11

poupou