由网友(怀念回不到的从前)分享简介:考虑我有2类:public class ComplicatedParent{// Lots of data}public class SimpleChild : ComplicatedParent{public string SomeAdditionalData { get; set; }public Simp...
考虑我有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
的实例。有没有构造孩子从父母的参考一个简单的方法,preserving父母的状态?
And SomeFunction
that returns instance of ComplicatedParent
. Is there a simple way to construct child from parent's reference, preserving parent's state?
实际上 ComplicatedParent
类和 SomeFunction
是第三方的,所以我不能改变的。
Actually ComplicatedParent
class and SomeFunction
are third party so I can't change them.
推荐答案
您无法自动在语言做到这一点。您可以Automaper或手动分配去做。
You can't do this automatically in the language. You can do it with Automaper or by manual assignments.
相关推荐
最新文章