How to deep copy a class without marking it as Serializable

前端 未结 7 552
自闭症患者
自闭症患者 2021-01-04 00:09

Given the following class:

class A
{
    public List ListB;

    // etc...
}

where B is another class that may inheri

7条回答
  •  孤独总比滥情好
    2021-01-04 00:40

    Can't you do this?

    [Serializable]
    class A
    {
         ...
        [NonSerialized]
        public List ListB;
        ....
    }
    

    And then refer to How do you do a deep copy of an object in .NET (C# specifically)? for a cloning function

提交回复
热议问题