Вот общий класс, с которым я работаю:
public interface IRepository<T> where T : EntityObject
{
RepositoryInstructionResult Add(T item);
RepositoryInstructionResult Update(T item);
RepositoryInstructionResult Delete(T item);
}
public class Repository<T> : IRepository<T> where T : EntityObject
{
RepositoryInstructionResult Add(T item)
{ //implementation}
RepositoryInstructionResult Update(T item);
{ //implementation}
RepositoryInstructionResult Delete(T item);
{ //implementation}
}
Теперь я пытаюсь время от времени изменять поведение методов, когда t : определенный тип. Возможно ли что-то вроде следующего? Эта конкретная попытка дает ошибку (Ошибка 5: Частичные объявления «Репозиторий» должны иметь имена параметров одного типа в том же порядке).
public class Repository<Bar> //where Bar : EntityObject
{
RepositoryInstructionResult Add(Bar item)
{ //different implementation to Repository<T>.Add() }
//other methods inherit from Repository<T>
}