开发者

deep copy cloning via serialization

开发者 https://www.devze.com 2023-01-19 12:07 出处:网络
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 pa

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号