Consider the following:
public class MyParentClass {
public int MyInt { get; set; }
}
public class MyChildClass : MyParentClass
{
}
public class AnotherClass
{
public MyChildClass GetChildClassFromParentClass(MyParentClass parent)
{
return new MyChildClass() { MyInt = parent.MyInt };
}
}
Since MyParentClass
and MyChildClass
share this 'relationship', I'm wondering why it's not possible to clone the class into it's child without the manual step of copying values across. Maybe we can't guarantee that MyChildClass
has dependencies being injected which causes a problem, but then can't the language feature permit this if there is a parameterless constructor defined then?
Let me be clear I know I'm wrong here, there definitely are scenarios which make this a language feature that isn't feasible or safe, I'd like to know what those scenarios are.
I don't want an opinion, this shouldn't be an opinion-based discussion. There are reasons this isn't a feature.