I have my repositories setup like below.
interface IRepository<T> where T : DataRow
{
T Get(int key);
}
interface ICartonRepository : IRepository<CartonDataRow>
{
}
class CartonRepository : ICartonRepository
{
public CartonDataRow Get(int key)
{
}
}
I also have a PackRepository which is defined in the same way as the CartonRepository. What I would like to do is something like the following.
IRepository<DataRow> repository;
switch (rowType)
{
case Carton:
repository = new CartonRepository();
break;
case Pack:
repository = new PackRepository();
break;
}
Is there a way I can achieve this?
For C# 3.5 you will have to add the following:
Then change
CartonRepositorytoclass CartonRepository : Repository<CartonDataRow>(I do not think you needICartonRepository, but you can use it if you want). Then