In a situation where I have two classes, abstract A, and B : A,
Is it possible to have a method within A, that implicitly returns a new instance of B? By implicitly, I mean that the type of B is never actually specified in code, but implied from the context. In code terms,
abstract class A
{
A New() => return new this; //this isnt valid but illustrates desired functionality
}
class SomeTypeOfDerivedClass1 : A
{}
class SomeTypeOfDerivedClass2 : A
{}
usage would be similar to this:
var someType = new SomeTypeOfDerivedClass1();
var someType2 = new SomeTypeOfDerivedClass2();
var newInstance = someType2.New(); // assigned new instance of SomeTypeOfDerivedClass2
newInstance = someType1.New(); // assigned new instance of SomeTypeOfDerivedClass1