Given the following class:
class A
{
public List<B> ListB;
// etc...
}
where B
is another class that may inherit/contain some other classes.
Given this scenario:
A
is a large class and contains many reference types- I cannot mark
B
as[Serializable]
as I don't have access to source code ofB
The following methods to perform deep copying do not work:
- I cannot use
ICloneable
orMemberwiseClone
as classA
contains many reference types - I cannot write a copy constructor for
A
, as the class is large and continuously being added to, and contains classes (likeB
) that cannot be deep copied - I cannot use serialization as I cannot mark a contained class (like
B
, where no source code available) as[Serializable]
How can I deep copy class A
?
your interface IDeepCopy is exactly what ICloneable specifies.
and with more friendly implementation :