これが私が扱っているジェネリッククラスです:
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>
}