Thursday, March 31, 2011

How do I create a method for deep cloning a usercontrol

I would like to create a deep clone of a usercontrol in my program. How do this. thanks

From stackoverflow
  • If you use MemberwiseClone() you will get a shallow copy which is probably not what you want as it will not be a true "replica". If you don't mind the two UserControls sharing references to child objects then MemberwiseClone() should do the trick. Otherwise you will have to write your own implementation to support your requirements.

  • Andrew is correct. If you want to do a deep clone, you'll need to add a method to your usercontrol that returns a deep clone.

    This gets annoying, because you then need to call this Deep Clone method on each reference type within your usercontrol and so-on.

    The IClonable interface was supposed to facilitate this pattern, but it was completely bungled and is largely useless.

0 comments:

Post a Comment