Deep Copy via Serialization

M

Magnus

Hi,

I've tried to to a deep copy of an serializable object (generated by
creating a xml Schema and then genrate classes with xsd.exe) using
serialization (xmlSerializer)
When I'm using a memory stream to serialize and deserialize, it fails
when trying to deserialize it (at position {0,0}
But when I'm using a file stream (store the file to c:\temp) and
desierialize it, it works just fine.

Why? Whats wrong with the memory stream? Known serialization bug?


/Magnus
 
T

the.duckman

Iv'e done this successfuly a long time ago using binary formatter and a
memorystream.

I then discontinued the practice after finding several problems
(including speed of execution).

I prefere instead to use the method pointed out here:
http://www.agiledeveloper.com/articles/cloning072002.htm

This particular concept is working very well and the code running under
it is fast(ish) and very stable.

-dm
 
M

Magnus

Thanks fo the tip, but the auto generated code does not implement the
IClonable interface... (?)
Maybe it's possible to use the partial class concept to implement
IClonable in a partial part of the autogenerated code...

And I do not want to create a copy constructor to set sometimes lots
and lots of property values

/Magnus
 
N

Nick Hounsome

Magnus said:
Thanks fo the tip, but the auto generated code does not implement the
IClonable interface... (?)
Maybe it's possible to use the partial class concept to implement
IClonable in a partial part of the autogenerated code...

Unless the autogenerated uses "partial" that wont work without some sort of
hack because ALL partial parts of a class must declare it as partial :-(
 
M

Magnus

Yes i know, and the autogenerated code from xsd do declare the classes
as partial.

But do all partial classes need to declare the base class and/or
interfaces?
The question is if it is possible to add some interfaces and or a base
class to a autogenerated partial class?
This must be really easy to test :)

/Magnus
 
M

Magnus

Adding an interface to one of the partial classes was enough for the
compiler to accept the whole class...
But it is still boring and time consuming to copy all property fields
with the IClonabe and copy constructor combination...
I still want a generic solution...

/Magnus
 

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

Top