473,666 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deep Copy via Serialization

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

Apr 10 '06 #1
5 2016
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/articl...ning072002.htm

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

-dm

Apr 10 '06 #2
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

Apr 10 '06 #3

"Magnus" <su*****@hotmai l.com> wrote in message
news:11******** **************@ t31g2000cwb.goo glegroups.com.. .
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 :-(
Apr 10 '06 #4
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

Apr 10 '06 #5
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

Apr 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2182
by: ahaupt | last post by:
Hi all, I'm implementing the Clone() method through the ICloneable interface and don't quite know how deep I need to go for a deep copy. Example: class A: ICloneable { object _val;
1
2335
by: oDDskOOL | last post by:
I realized today that the Hashtable.Clone only produces a shallow copy... that makes me go mad that M$ doesn't even provide a deep copy ctor for the Hashtable class ! mighty tech ducks might reply "oh but what if the types in hastable don't have copy ctors defined? that could lead to dangerous situations". well, but was it a significant effort to provide a copy ctor / deep clone method to this class for objects that provide the...
5
25639
by: BenW | last post by:
Hello, What is the easiest way to make "deep copy" of my Hashtable? How about with other Collection classes in C#, any documents available? I don'r actually understand why Framework's Collection classes does not support deep copy methods by theself, only Clone with shallow copy.
4
3033
by: jjkboswell | last post by:
I have an XSD which I have generated a class from using the xsd.exe tool. My XSD contains complex types within it, so that the generated class has member variables which are of types that are also defined in the XSD. I deserialize XML data into instances of that class, and serialize back to XML. So far so good. However, in my code I have the concept of wanting to create new copies of these deserialized objects and modifying some of...
3
8746
by: raylopez99 | last post by:
The "C# Cookbook" (O'Reilly / Jay Hilyard), section 3.26, is on deep cloning versus shallow cloning. The scanned pages of this book are found here: http://www.sendspace.com/file/mjyocg (Word format, 3 pp) My question, coming from a C++ background where deep copying is done, is why in C# you would do either deep or shallow copying as suggested by O'Reilly (using the "ICloneable" inhereited interface), at least for the .NET framework. ...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6192
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.