【问题标题】:MonoTouch AOT compiler not constructing Dictionary types in generic classesMonoTouch AOT 编译器不在泛型类中构造字典类型
【发布时间】:2012-05-24 06:10:02
【问题描述】:

在 MonoTouch 中,当创建具有 Dictionary 的泛型类型时,该 Dictionary 使用该类型的泛型类型参数作为其值的类型,AOT 编译器不会构造所需的 Dictionary 类型,从而导致 iOS 设备上出现运行时错误它会尝试调用 JIT 编译器。

public class Foo<T>
{
    private Dictionary<int, T> d = new Dictionary<int, T>();
    ...
}

var foo = new Foo<string>(); // Runtime error.

有一种解决方法 (posted on the Catalysts blog) 涉及在程序的其他地方显式声明所需的任何构造类型:

var x = new Dictionary<int, string>();

但这有点乱。 有更好的解决方法吗?

此外,在我看来,所有信息在编译时都已存在,因此 AOT 编译器应该能够构造所需的类型。因此,这是一个可行的编译器功能吗(我们可能会在未来的版本中获得)?

【问题讨论】:

  • 您提交过关于此的错误吗? bugzilla.xamarin.com 是你的朋友。如果您报告它,它可能会在未来的版本中得到修复,除非它是泛型的旋钮限制。
  • @Krumelur 我猜这可能是一个已知的限制,所以只是在一个更好的解决方法之后,但我想我也会提交一个错误报告。

标签: c# generics xamarin.ios aot


【解决方案1】:

此问题现已修复,因此无需解决方法:

https://bugzilla.xamarin.com/show_bug.cgi?id=5316

【讨论】:

    猜你喜欢
    • 2010-10-16
    • 2016-06-11
    • 2017-11-18
    • 2017-12-30
    • 2016-04-05
    • 1970-01-01
    • 1970-01-01
    • 2019-07-05
    • 1970-01-01
    相关资源
    最近更新 更多