how to deep copy a class without marking it as serializable

Posted by Gaddigesh on Stack Overflow See other posts from Stack Overflow or by Gaddigesh
Published on 2010-03-30T12:22:48Z Indexed on 2010/03/30 12:33 UTC
Read the original article Hit count: 480

Filed under:
|
|

I came across many questions on deep copy but non of them helped me I have a class say

class A
{
     ...
    public List<B> ListB;
    ....
}

where B is again another class which inturn may inherit/contain some other classes Take this scenario

  1. A is a very huge class and contain many reference types
  2. I can not mark B as serializable as i don't have access to source code of B(Though I can Mark A as serializable)

Problem:below methods to perform deep copy does not work because

  1. I can not use Iclonable, memberwise clone technique as class A conatins many reference types
  2. I can not write a copy constructor for A , as the class is huge and keeps growing and contained classes (Like B) can't be deep copied
  3. I can't use serialization technique as i can not mark conatined class(like B, for which no source code avilaable) as serializable

So how can I deep copy the object of Class A?
(I read about "surrogate serialization" technique some where but not clear)

© Stack Overflow or respective owner

Related posts about c#

Related posts about deep