How to create deferenced copy of an object in C#? -


i have entity use bind data wpf ui. in need create copy of entity can use "original" data anytime.

just creating new object , assigning carries references it. need copy of entity object has no effect of changes made on source.

my entity contains value type properties , several nested collections.

any suggestions/ideas on this?

you need write own copy constructor: shows how. http://msdn.microsoft.com/en-us/library/ms173116(v=vs.80).aspx

for collections need copy data too. array.copy work hashtable might need go far serialization or recreating table.

sometype[] myarray = new sometype[orig.count+ 1];  orig.copyto(myarray, 0); 

Comments

Popular posts from this blog

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -

jQuery clickable div with working mailto link inside -