Copy object without creating new instance
Posted on 2009-02-22
I have need to copy an object without creating a new instance of it. (i.e. DeepClone and Serialize won't do it) Example:
I have a routine for editing an object's content. I start by making a copy of the object, (that can be a new instance) then I change it's values, apply, change value, apply, etc. At some point I want to revert the original object back to its initial state. I can't use DeepClone against the copy because I need to return the same object that was passed in.
Note: this is just an example, I've got lots of cases where I need to repopulate an object's content without re-instantiating it. (i.e. any place where other routines have an handle to that instance of the object)
It seems to me that the code in DeepClone and Serialize must be able to do this, but I haven't see that code and so don't know what to call.