Given the following classes:
ClassA
{
public ClassA DoSomethingAndReturnNewObject()
{}
}
ClassB : ClassA
{}
ClassC : ClassA
{}
Is there a way to get ClassB
and ClassC
to inherit the method but customize the return type to their own class?
I prefer not to copy the method from ClassA and change the type there.
I need to get a ClassB
object when I call ClassB.DoSomethingAndReturnNewObject()
.
I need to get a ClassC
object when I call ClassC.DoSomethingAndReturnNewObject()
.
Something like calling a constructor based on current type like: this.GetType()
? But I have no clue how to actually do that.