非泛型方法 'Dictionary<Type, Type>.Add(Type, Type)' 不能与类型参数一起使用
The non-generic method 'Dictionary<Type, Type>.Add(Type, Type)' cannot be used with type arguments
我下面有类和接口实现
public interface IPageRepository<T> : IRepository
{
IList<T> GetPage(Criteria criteria, out int totalRows);
}
public interface ICategoryRepository : IPageRepository<Category>
{
// rest of the methods
}
public class CategoryRepository : BaseDap, ICategoryRepository
{
// method implementations
}
public class RepositoryFactory
{
private static readonly Dictionary<Type, Type> container = new Dictionary<Type, Type>();
static RepositoryFactory()
{
container.Add<ICategoryRepository, CategoryRepository>();
//Getting error here:
//The non-generic method 'Dictionary<Type, Type>.Add(Type, Type)' cannot be used with type arguments
}
}
我在其他项目中遵循了类似的模式并且在那里工作。
我在这里错过了什么?
您将类型参数与实际参数混淆了。你打算写
container.Add(typeof(ICategoryRepository), typeof(CategoryRepository));
我下面有类和接口实现
public interface IPageRepository<T> : IRepository
{
IList<T> GetPage(Criteria criteria, out int totalRows);
}
public interface ICategoryRepository : IPageRepository<Category>
{
// rest of the methods
}
public class CategoryRepository : BaseDap, ICategoryRepository
{
// method implementations
}
public class RepositoryFactory
{
private static readonly Dictionary<Type, Type> container = new Dictionary<Type, Type>();
static RepositoryFactory()
{
container.Add<ICategoryRepository, CategoryRepository>();
//Getting error here:
//The non-generic method 'Dictionary<Type, Type>.Add(Type, Type)' cannot be used with type arguments
}
}
我在其他项目中遵循了类似的模式并且在那里工作。 我在这里错过了什么?
您将类型参数与实际参数混淆了。你打算写
container.Add(typeof(ICategoryRepository), typeof(CategoryRepository));