【发布时间】:2015-08-25 02:45:17
【问题描述】:
我有以下具有泛型类型约束的泛型类型。
public class GenericType<T> where T: IFoo
{
}
然后我尝试从开放的泛型类型创建一个封闭的泛型类型。
var fooGenericType = typeof(GenericType<>).MakeGenericType (typeof(IFoo));
var intGenericType = typeof(GenericType<>).MakeGenericType (typeof(int));
在模拟器中运行时,尝试使用 int 作为预期的类型参数创建封闭的泛型类型失败。
但是,当在实际设备 (iPhone) 上运行时,它还将使用 int 创建一个封闭的泛型类型。 似乎它不尊重通用约束,但这仅发生在设备上。在模拟器上一切正常。
有什么想法吗?
【问题讨论】: