有没有办法从父参考构造子对象? [英] Is there a way to construct child object from parent reference?

查看:159
本文介绍了有没有办法从父参考构造子对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑我有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.

这篇关于有没有办法从父参考构造子对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆