Monodroid仿制药不协变?

IUn*_*own 2 generics mono covariance xamarin.android

编辑: 似乎证实协变仿制药尚不支持.要确保它在下一个版本中发布,请发送电子邮件至Xamarin并请求此功能.

以下代码给出了一个错误(在linq语句中).相同的代码在Microsoft clr c#4.0中正常工作.

错误:

Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<LinqTest.Person>' to 'System.Collections.Generic.IEnumerable<LinqTest.Entity>'. An explicit conversion exists (are you missing a cast?)
Run Code Online (Sandbox Code Playgroud)

码:

[Activity(Label = "LinqTest", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity {

    protected override void OnCreate(Bundle bundle) {
        base.OnCreate(bundle);

        var names = new List<string> {
                                         "Joe",
                                         "Bob",
                                         "Jim",
                                         "Jane"
                                     };

        IEnumerable<Entity> query =
            from e in names
            select new Person() {Name = e};

        SetContentView(Resource.Layout.Main);

        var button = FindViewById<Button>(Resource.Id.MyButton);

        button.Click += delegate {
                            button.Text = string.Format("{0}", query.Count());
                        };
    }
}

public class Entity {
    public string Name { get; set; }
}

public class Person : Entity {
    public string Workplace { get; set; }
}

public class Animal : Entity {
    public string FurColour { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我纠正还是错过了什么?如果是这样的建议重构这个?

此外,如果是这样,请考虑这是monodroid的官方功能请求 - 支持协变通用支持.:)

谢谢.

Rol*_*nge 5

MonoTouch和Mono for Android现在都不支持协方差.它将在未来版本中支持(可能在今年下半年的某个时间).