c#泛型类的具体覆盖

dav*_*ett 6 .net c# generics inheritance subtype

这是我正在使用的通用类:

 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}
 }
Run Code Online (Sandbox Code Playgroud)

现在我想在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>
 }
Run Code Online (Sandbox Code Playgroud)

rok*_*ken 6

public class BarRepository : Repository<Bar>
{ 
    RepositoryInstructionResult Add(Bar item) 
    { //different implementation to Repository<T>.Add() } 
    //other methods inherit from Repository<T> 
} 
Run Code Online (Sandbox Code Playgroud)