Re: Binding (copy)



On Mon, 26 May 2008 18:20:39 -0700, Tim Jarvis <tim@xxxxxxxxxxxxx> wrote:

Man, what an excellent answer.

<blush>

I'd just add that there is one other option that may or may not be
suitable depending on your obj. Object provides a shallow cloning
method called MemberwiseClone(), this would be fine if you were happy
to copy value types but leave reference types pointing to the original
referenced thing. (I would however re-itterate what Peter said, if in
doubt implement ICloneable, then you are in complete control)

Well, MemberwiseClone() is "protected" anyway. You can't use it except from within the class, and in that case you might as well implement ICloneable. If the class has non-cloneable reference types, this just pushes the problem down a layer, but who knows? Maybe that's not an issue here (either because a shallow clone is okay, or because the class has only cloneable members). :)

Pete
.