【发布时间】:2014-06-25 01:31:30
【问题描述】:
我有这样的课:
public sealed class Repository<T> : IRepository<T>
where T : RepositoryEntryBase, IRepositoryEntry, new()
{
/*Insert Stuff Here*/
}
我正在尝试像这样实例化这个类:
Repository<dynamic> v = new Repository<dynamic>();
我收到这样的错误:
类型“动态”不能用作泛型类型或方法“ServiceLibraries.Repositories.Repository”中的类型参数“T”。没有从“动态”到“Data.IRepositoryEntry”的隐式引用转换。
不过,MSDN 文档说明如下:
在编译时,假定类型为动态的元素支持任何操作。
我有什么遗漏吗?关于如何解决这个问题的任何想法?
【问题讨论】:
-
如何定义“IRepository
”(其中 T: ...?) -
公共接口 IRepository
where T : IRepositoryEntry, new()