c# Concrete override of generic class

.net, c#, generics, inheritance, subtype

Solution

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

Problem

Here's the generic class I'm working with: ``` 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} } ``` Now I'm looking to occasionally alter the behavior of the methods when t : a specific type. Is something like the following possible? This particular attempt gives an error (Error 5: Partial declarations of 'Repository' must have the same type parameter names in the same order). ``` public class Repository<Bar> //where Bar : EntityObject { RepositoryInstructionResult Add(Bar item) { //different implementation to Repository<T>.Add() } //other methods inherit from Repository<T> } ```

Original source