我正在尝试做类似于这样的事情:
public interface IRepository<T>
{
T Get<T>(int id);
}
public interface IFooBarRepository : IRepository<Foo>, IRepository<Bar>
{
}
IFooBarRepository repo = SomeMethodThatGetsTheActualClass();
Foo foo = repo.Get<Foo>(1);
我收到了一个警告:
类型参数“T”与外部类型“IRepository”的类型参数同名
还有一个错误:
以下方法或属性的调用是模糊的:“IRepository.Get(int)”和“IRepository.Get(int)”
你有什么想法可以让这个模式工作?
T2 Get<T2>
...但那么T
的意义是什么呢? - Jon Skeet