I wrote this valid piece code, which made me wonder if there was a name for it:
public class GenericObject<T> {
public T Obj { get; set; }
}
public class DerivedClass: GenericObject<DerivedClass> { }
This leads to the capability of:
var x = new DerivedClass();
x.Obj = x;
x.Obj.Obj = x;
x.Obj.Obj.Obj = x;
// ...
x.Obj.Obj.Obj.Obj.Obj.Obj.Obj.Obj.Obj.Obj...Obj = x;
Which is sure to raise a lot of eyebrows depending on the use case.
Is there a name for this? If so, what is it called, and what is a practical application?
class C { public C Obj; }
. Note that you can't dox.Obj.Obj = x;
without first doingx.Obj = x;
, as you'll get a NullReferenceException.