I have an abstract class:
public abstract class LMManager<ENTITY, ILM_ENTITY> where ENTITY : ILM_ENTITY, IActiveRecord, ICallOnCreated, new( )
ENTITY is some kind of DataObject, ILM_ENTITY, IActiveRecord, and ICallOnCreated are interfaces that the DataObject implements.
Typically, I subclass this guy with classes something like
public class JobManager : LMManager<Job, ILMJob>
public class JobViewManager : LMManager<vwJob, ILMJobView>
Now, I have a case where two of the sub-classes have some code in common, so I want to insert another layer in between, something like
public abstract class JobManagerBase : LMManager<ENTITY, ILM_ENTITY>
and then change the other two guys to
public class JobManager : JobManagerBase<Job, ILMJob>
public class JobViewManager : JobManagerBase<vwJob, ILMJobView>
In the definition of my JobManagerBase, I get four errors related to ENTITY:
- Must be a non-abstract type with a public parameterless constructor
- No boxing conversion or type parameter conversion from ENTITY to ICallOnCreated
- No boxing conversion or type parameter conversion from ENTITY to IActiveRecord
- No boxing conversion or type parameter conversion from ENTITY to ILM_ENTITY
Is it terribly obvious what I am missing?
Your
JobManagerBaseattempts to useLMManagerwith the parametersENTITYandILM_ENTITY.Since these parameters do not meet your constraints, you get an error. (What if someone makes a
JobManagerBase<int, string>?)You need to add generic parameters and the same
whereclause toJobManagerBaseto ensure that its parameters meet the constraints required forLMManager.