I have these multiple versions of these two classes:
public class Contests : List<Contest> { }
public class Contest {
// stuff specific to Contest;
public Contests parent;
public void Attach() {
parent.Add(this);
}
}
And here's another:
public class Transactions : List<Transaction> { }
public class Transaction {
// stuff specific to Transaction;
public Transactions parent;
public void Attach() {
parent.Add(this);
}
}
So that I don't repeat code, can I take out the Attach into a base class using generics?
public class MBData<T> {
public T parent;
public void Attach() {
T.Add(this);
}
}
I tried with the following but I receive an error about not being able to convert between Contests
and MBDatas<MBData<Contests>>
.
public class MBDatas<S> : List<S> { }
public class MBData<B> where B : MBDatas<MBData<B>> { }
public class Contests : MBDatas<Contest> { }
public class Contest : MBData<Contests> { }