Microsoft Dot Net Master

Microsoft Dot Net Master
Microsoft Dot Net Master

Monday, March 18, 2013

Seriaization


Object Serialization is a process through which an object's state is transformed into some serial data format, such as XML or binary format, in order to be stored for some later use. In other words, the object is "dehydrated" and put away until we need to use it again.

Some good uses for serialization/deserialization include: 
  1. Storing user preferences in an object.
  2. Maintaining security information across pages and applications.
  3. Modification of XML documents without using the DOM.
  4. Passing an object from on application to another.
  5. Passing an object from one domain to another.
  6. Passing an object through a firewall as an XML string. 

class Person
{
    private String personName;
    private Int32 personAge;

    public String Name
    {
        get
        {
            return personName;
        }
        set
        {
            personName = value;
        }
    }

    public Int32 Age
    {
        get
        {
            return personAge;
        }
        set
        {
            personAge = value;
        }
    }
}
Person oPerson = new Person();
oPerson.Name = "Sandeep Rauniyar";
oPerson.Age = 25;

we wanted to save a copy of this object just as it is at this very moment. We could serialize it as an XML document that would look something like this:

   
     Sandeep Rauniyar


     25

No comments:

Post a Comment