I have two different classes deriving from one base class. They each have a collection deriving from another base class, but different derived class.
class MasterA : MasterBase<ClientA>
class MasterB : MasterBase<ClientB>
public class MasterBase<ClientClass> where ClientClass : ClientBase
{
public List<ClientClass> Clients;
}
Class ClientA : ClientBase
Class ClientB : ClientBase
Class ClientBase
What I want is to have a UserControl which works with the parent/child lists of both Master/Client of either type (A or B).
public class Test<MasterClass> where MasterClass : MasterBase<ClientBase>
{
GenericRepository<MasterClass> repo = new GenericRepository<MasterClass>();
MasterClass master = repo.GetAll;
// do some changes to (base fields of) the master collection and its client collection !
repo.SaveOrUpdate(master);
}
But…. I can’t instantiate that Test class..
var t = new Test<MasterA>();
>> There's no implicit reference conversation from MasterA to MasterBase<ClientBase>
So, is there some way I can modify the Test class to be able to do what I’ve indicated?
would really appreciate some hints.
Not knowing what constraints you were working under, originally posted this as a comment.
Would
be a suitable change to your codebase? Obviously, this line would have to change also:
The issue is that, just because there is an inheritance relationship between two classes,
XandY, that does not mean that the generic typesG<X>andG<Y>have the same (or any) inheritance relationship. SoMasterBase<ClientA>does not inherit fromMasterBase<ClientBase>