いいえ、まったくありませんが、これを行うことができます:
// base interface for entity types
interface IEntity
{
}
class Employees : IEntity
{
}
class Students : IEntity
{
}
interface IRepository<T1, T2> where T1:IEntity where T2:IEntity
{
T1 GetAll();
T2 GetAll();
}
class PersonRepository : IRepository<Employees,Students>
{
Employees GetAll();
Students GetAll();
}
残念ながら、型パラメーターの数を動的に変更することはできません。
または、これを行うこともできます。
// base interface for entity types
interface IEntity
{
}
class Employees : IEntity
{
}
class Students : IEntity
{
}
interface IRepository
{
RegisterEntities(IEnumerable<IEntity> entities);
IEnumerable<IEntity> GetAll();
}
class PersonRepository : IRepository
{
IEnumerable<IEntity> GetAll()
{
// Todo
}
}
これは、従業員と学生が基本インターフェースを共有しているため、同じリポジトリに追加できることを意味します。後でそれらを抽出し、簡単にアクセスできるようにIEntityに共通のフィールド(名前、年齢など)を配置できます。