what is meant by serialization?

Posted by balajirnaukri-12656 under ASP.NET on 4/26/2012 | Points: 10 | Views : 2328 | Status : [Member] | Replies : 5
I have seen some class being declared as [serializable].What is the exact use of that.
And what is meant by serialization?

Thanks and Regards
Balaji.R
ASP.NET Devloper
Solve-IT corp



Responses

Posted by: Sakthi.Singaravel on: 4/26/2012 [Member] Silver | Points: 25

Up
0
Down
See this for definition..

http://msdn.microsoft.com/en-us/library/ms233843.aspx

Regards,
Singaravel M

balajirnaukri-12656, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/26/2012 [Member] Silver | Points: 25

Up
0
Down
Refer this link for example and its uses...

http://www.c-sharpcorner.com/UploadFile/Nimusoft/Serialization106262007072102AM/Serialization1.aspx

Regards,
Singaravel M

balajirnaukri-12656, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Veerac85 on: 4/30/2012 [Member] Starter | Points: 25

Up
0
Down
if you would like to know about XML Serialization refer to this article that would explain how to convert objects into xml string using XML Serializer class.
http://technico.qnownow.com/2012/04/26/xml-serialization-in-c/

if you are interested in cloning objects using serialization, refer to below article
http://technico.qnownow.com/2012/03/12/shallowdeep-cloning-of-object-in-c/

balajirnaukri-12656, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 5/2/2012 [Member] Starter | Points: 25

Up
0
Down
Serialization is the process of converting complex objects into stream of bytes for storage. Deserialization is its reverse process, that is unpacking stream of bytes to their original form. The namespace which is used to read and write files is System.IO. For Serialization we are going to look at the System.Runtime.Serialization namespace. The ISerializable interface allows you to make any class Serializable.
Here are the following steps that we are going to do to create a serializable class and test it.
. Create a custom class named Employee and assign properties.
. Define the serialization functions.
. Create a main class and instantiate our Employee class.
. Serialize the object to a sample file.
. Deserialize the values by reading it from the file.
Defining Employee class and properties
Our custom class Employee should be derived from the ISerializable interface and should hold the Serializable attribute. Here is the code snippet.

using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary; namespace MyObjSerial
{
[Serializable()] //Set this attribute to all the classes that want to serialize
public class Employee : ISerializable //derive your class from ISerializable
{
public int EmpId;
public string EmpName;

//Default constructor
public Employee()
{
EmpId = 0;
EmpName = null;
}
}
}


balajirnaukri-12656, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/23/2012 [Member] Starter | Points: 25

Up
0
Down
1) serializable is the process by convert object into stream of bytes..

2) Serialization is an easy way to convert an object to a binary representation that can then be e.g. written to disk or sent over a wire.

NET offers 2 serializers: binary, SOAP, XML. The difference between binary and SOAP is:

binary is more efficient (time and memory used)
binary is not human-readable. SOAP isn't much better

using System;

using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace MyObjSerial
{
[Serializable()] //Set this attribute to all the classes that want to serialize
public class Employee : ISerializable //derive your class from ISerializable
{
public int EmpId;
public string EmpName;

//Default constructor
public Employee()
{
EmpId = 0;
EmpName = null;
}
}
}


hope this will help

regards


sriram

balajirnaukri-12656, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response