The current class library I am working on will have a base class (Field) with over 50 specific \"field\" types which will inherit from \"Field\" and nested for maintain readabil
FieldA inherits a reference to class FieldA which inherits a reference to class FieldA which inherits a reference to class FieldA which inherits a reference to class FieldA which inherits a reference to class FieldA which inherits a reference to class FieldA which inherits a reference to class FieldA which...
It works because that's what you told it to do.
Field
has a public nested-class named FieldA
FieldA
inherits from Field
FieldA
from FieldA
.The reference isn't creating infinite chains, it is simply pointing to the same class. (some test code)
When you access FieldA.FieldA
, the latter FieldA
is accessible due to the fact that the former FieldA
is an instance of Field
so the latter FieldA
actually access Field.FieldA
Sounds like you wanted something like:
abstract class Field
{
public int Length { get; set; }
}
public class FieldA : Field
{
public static void DoSomething()
{
Console.WriteLine("Did something.");
}
}
Otherwise you're defining a base class with an inner class in it, which inheritorrs will also get. So when you inherit from the outer class to make the inner class, you're starting a loop.