考虑我有2类:有没有办法从父引用构造子对象?
public class ComplicatedParent
{
// Lots of data
}
public class SimpleChild : ComplicatedParent
{
public string SomeAdditionalData { get; set; }
public SimpleChild(string arg) : base()
{
SomeAdditionalData = arg;
}
}
而且SomeFunction
返回的ComplicatedParent
实例。是否有一种简单的方法从父母的参考构建孩子,保护父母的状态?
其实ComplicatedParent
类和SomeFunction
是第三方,所以我不能改变它们。