Code Reference A collection of code for my reference (and perhaps other people too)

19Nov/090

Cloning an object – easy way

To clone an object MS says your object should inherit from IClonable. I have read many good and bad comments on this which mention it not being able to do a deel copy and whatever. A quick search will give you lots to read.
Using IClonable is a valid option.

Then I found one idea that I really liked. Serialize your object, than unserialize it. Done!

Things to note:
* Your object must be serializable.
* I have not tested if this works with complex object.
* I have not tested how this handles lazy bindings with nHibernate
* For simple object works great!

TODO: test with complex objects

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.