It allows the developer to save the state of an object and recreate it as needed, providing storage of objects as well as data exchange. Through serialization, a developer can perform actions like sending the object to a remote application by means of a Web Service, passing an object from one domain to another, passing an object through a firewall as an XML string, or maintaining security or user-specific information across applications.
///To de-serialize it back to the object,/// Serializes an Object /// /// Object to SerializedObject ///serialized string(xml) public string SerializeObject(Object objectInstance) { System.IO.StringWriter stringwriter = new System.IO.StringWriter(); System.Xml.Serialization.XmlSerializer serilizer = new System.Xml.Serialization.XmlSerializer(objectInstance.GetType()); serilizer.Serialize(stringwriter, objectInstance); return stringwriter.ToString(); }
////// De-Serializes an Object /// /// serialized string(xml) ///public Object DeSerializeObject(string serializedObject) { var stringReader = new System.IO.StringReader(serializedObject); var serializer = new System.Xml.Serialization.XmlSerializer(typeof(Object)); return serializer.Deserialize(stringReader) as Object; }