My program structure:
I have two abstract classes. A TestBase class for different types of tests, and a TestBaseLayer, for collections of the different types of tests. They look like this:
public abstract class TestBaseLayer<T> where T : TestBase
{
public abstract List<T> Tests { get; set; }
}
Each TestBase has a reference to the TestBaseLayer that contains it:
public abstract class TestBase
{
public TestBaseLayer<TestBase> BaseLayer { get; set; }
public TestBase(TestBaseLayer<TestBase> layer){
BaseLayer = layer;
}
}
I have a class TestPointLayer which is a TestBaseLayer of TestPoint. TestPointLayer and TestPoint look like this:
public class TestPoint : TestBase
{
public TestPoint(TestPointLayer layer) : base(layer as TestBaseLayer<TestBase>) { }
}
public class TestPointLayer : TestBaseLayer<TestPoint>
{
public override List<TestPoint> Tests { get; set; }
}
The problem:
When I create a TestPoint instance passing a TestPointLayer object to the TestPoint constructor, I need to call the base constructor with the TestPointLayer as a TestBaseLayer. Which I thought in theory it WAS, but my layer as TestBaseLayer<TestBase>
returns null?