deep copy (Clone) on System.Collections.Generic.Dictionary ?

  • Thread starter Thread starter semedao
  • Start date Start date
S

semedao

Hi,
what is the best way to perform deep copy (Clone) on class that inherit from System.Collections.Generic.Dictionary ?
 
Serialize and deserialise to a memory stream
Use a binary formater, its faster. You may have to implement a surrogate if
it isnt serialiazable and the contents will need to be too.
 
Hi,

If either the keys or values aren't serializable, or if you don't know
whether they will be, then iterate over the key-value pairs and copy them
into a new instance of your class. If the keys or values are ICloneable
then store the result of the Clone method, otherwise check whether they are
serializable and serialize/deserialize them as per Ciaran's response.

--
Dave Sexton

Hi,
what is the best way to perform deep copy (Clone) on class that inherit from
System.Collections.Generic.Dictionary ?
 
Hi,

I should add that if you have typed the key and value as value-types then
you'll just have to iterate the dictionary and copy them into a new
instance - no ICloneable or serialization/deserialization required.

--
Dave Sexton

Hi,
what is the best way to perform deep copy (Clone) on class that inherit from
System.Collections.Generic.Dictionary ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top