Why Serialization

H

Henry Jones

I read a bit on Serialization and came up with the following definition:

The System.Runtime.Serialization namespace contains classes that can be used
for serializing and deserializing objects. Serialization is the process of
converting an object or a graph of objects into a linear sequence of bytes
for either storage or transmission to another location. Deserialization is
the process of taking in stored information and recreating objects from it.



My question is why would someone want to do this? In doing some more
investigation, I understand you can an array list, or a TreeView. Can't you
just create the same thing in a new class or on another form by doing a new
query? Is it such a big deal?



Please help me figure out what I am missing by all this.



Thanks
 
C

Cor Ligthert [MVP]

Henry,

For a lot of situations, one of them can be that you want to store a control
in the state as it is, but you can also use it to sent an object in the
state it is pver the line without XML serialization.

It is also used to make a deep copy of objects by the way, because there are
only few classes who have methods for that. (The dataset and the datatable
have those by instance).

It is simple to do, see here a sample of that.

http://www.vb-tips.com/dbpages.aspx?ID=7ffd296f-9e81-47e6-88dc-61641f5c8d9d

I agree that this is not the only method, but a lot of people like to do it
this way.

I hope that this helps sofar,

Cor
 
H

Henry Jones

I can understand that you can do it, but why would you need to do it? You
said that you can store a control in the state it is, but for the array
example, why can't you just pass they array as an object?

Thanks,
Henry
 
K

Kevin Spencer

You can create a Serializable class, and save a serialized version of the
class in its current state in the file system as a file. Any application may
then de-serialize the class back to its pre-serialized state from the file.
For example, I have an application that saves "Document" instances to an XML
file. Because of this, the XML can not only be de-serialized back to its
original class, but it can be transformed into any other "document" format
via XSLT. We have applications that do logging via creating XML-serializable
class, each instance of which represents an "entry." We can (and do) send
these logs or selected portions of them via email as text or HTML, display
them as a web page using ASP.Net with XML/XSLT. We can format them and apply
specific filtering logic to transform them any way we please, even possibly
(but have not yet) transform certain types of statistical data to images,
such as pie charts and graphs.

There are, of course, quite a few other reasons for wanting to serialize
classes to files, to file streams, and to Network streams (such as is done
with WCF, Remoting, and Web Services. Depending upon the reason, there are
many possible uses for it.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
 
C

Cor Ligthert [MVP]

Henry,

As I wrote in my previous reply you cannot deep copy an arraylist object.
(You can copy an array, but if that contains reference types not more than
as a shalow copy)

The arraylist (as all methods inheriting from the list class) contains a
clone and the copyto method.

You can read more about this methods including the deep copy if you take a
deeper look at the Clone and CopyTo methods on this page.

http://msdn2.microsoft.com/en-us/library/system.collections.arraylist_methods.aspx

I hope this helps,

Cor
 
G

Guest

If everything in the object hierarchy is serializable, then making a deep
copy of an object is trivial using serialization. This is very useful, as
you do not need to maintain copy methods for each class in the hierarchy
(which would need to be modified every time you add or remove fields of the
class).
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
C# Code Metrics: Quick metrics for C#
 

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