PC Review


Reply
Thread Tools Rate Thread

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

 
 
semedao
Guest
Posts: n/a
 
      19th Dec 2006
Hi,
what is the best way to perform deep copy (Clone) on class that inherit from System.Collections.Generic.Dictionary ?
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2lhcmFuIE8nJycnRG9ubmVsbA==?=
Guest
Posts: n/a
 
      19th Dec 2006
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.


--
Ciaran O''''Donnell
http://wannabedeveloper.spaces.live.com


"semedao" wrote:

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

 
Reply With Quote
 
Dave Sexton
Guest
Posts: n/a
 
      19th Dec 2006
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

"semedao" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Hi,
what is the best way to perform deep copy (Clone) on class that inherit from
System.Collections.Generic.Dictionary ?


 
Reply With Quote
 
Dave Sexton
Guest
Posts: n/a
 
      19th Dec 2006
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

"semedao" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Hi,
what is the best way to perform deep copy (Clone) on class that inherit from
System.Collections.Generic.Dictionary ?


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is System.Collections.Generic.dictionary order preserved? Magnus.Moraberg@gmail.com Microsoft C# .NET 4 19th Jun 2008 09:40 AM
Method not found: 'System.Collections.Generic.Dictionary`2 Monty Microsoft ASP .NET 3 6th Nov 2007 06:24 AM
The generic type 'System.Collections.ObjectModel.Collection`1' was used with the wrong number of generic arguments in assembly 'mscorlib' svkuery@gmail.com Microsoft Dot NET Framework 1 28th Mar 2007 08:05 PM
Case insensitive System.Collections.Generic.Dictionary pamela fluente Microsoft VB .NET 2 4th Feb 2007 03:55 PM
Collections: Does 'Add' make a deep copy? Steve Hiemstra Microsoft Dot NET Framework 2 12th May 2006 07:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:48 AM.