Неуниверсальный метод 'Словарь.Add (Type, Type) 'нельзя использовать с аргументами типа - PullRequest
0 голосов
/ 12 октября 2018

У меня есть классы и реализация интерфейса ниже

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
    }
}

Я следовал аналогичному шаблону в другом проекте, и он работает там.Что мне здесь не хватает?

1 Ответ

0 голосов
/ 12 октября 2018

Вы перепутали аргументы типа с реальными аргументами.Вы хотели написать

 container.Add(typeof(ICategoryRepository), typeof(CategoryRepository));  
...