I have an abstract class which has generic
public abstract class BaseService<T>
{
public abstract void Read(T param);
}
and I have few other classes which is extending this abstract class
public class ServiceOne : BaseService<DTOParam>
{
public override void Read(DTOParam param)
{
//Do something with this DTOParam
}
}
//Other class
public class ServiceTwo : BaseService<DTOParamtwo>
{
public override void Read(DTOParamtwo param)
{
//Do something with this DTOParamtwo
}
}
I have been trying to Instantiate these class like
BaseService<T> bs = new ServiceOne();
which is throwing and error as
Cannot implicitly convert type ServiceOne to BaseService<T>
If you remove the generic it is working fine, What I am missing here? Or is the above approach not possible at all.