有没有办法从父参考构造子对象?没有办法、对象

由网友(怀念回不到的从前)分享简介:考虑我有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.

推荐答案

您无法自动在语言做到这一点。您可以Aut​​omaper或手动分配去做。

You can't do this automatically in the language. You can do it with Automaper or by manual assignments.

阅读全文

相关推荐

最新文章