This is similar to compilation, although it is more related to hair:
class ParentClass<C, T> where C : ChildClass<C, T> { public void AddChild(C child) { child.SetParent(this); } } class ChildClass<C, T> where C : ChildClass<C, T> { ParentClass<C, T> myParent; public void SetParent(ParentClass<C, T> parent) { myParent = parent; } }
This solution uses a recursively related type parameter that approximates the "type itself."
I must link Eric Lippert's article with this template: Curious and Curious
source share