deep copy cloning via serialization
I came accross this:
http://www.codeproject.com/KB/tips/SerializedObjectCloner.aspx
and would like to use it to deep copy a object graph. Is it sufficient to mark all the classes that potentially participate in the object graph with:
[Serializable()]
and then invoke the clone method as suggested in the article?
I have my doubts tha开发者_StackOverflowt it is that simple and I may have to implement more?! Thought I ask the experts first before I dig any deeper.
Thanks.
Christian
Putting SerializableAttribute
on a class means that all the fields of the object (except those you attribute with NonSerialized
) will be serialized (and so they, themselves, need to be serializable). For simple cases that is enough, but for more complicated objects, you might want to look at implementing ISerializable
, which will transparently work with the code in the article. It very much depends on your exact situation. For simple cases, SerializableAttribute
by itself is enough.
精彩评论