interviews.dotnetthread.com

↑ Grab this Headline Animator

Friday, July 11, 2008

Write code for Deserialize an object (using XML Serialization).

// Casting deserialized XML object to our own class
MyClass deSerializedClass = (MyClass) DeSerializeAnObject(xmlObject);
private object DeSerializeAnObject(string xmlOfAnObject)
{
MyClass myObject = new MyClass();
System.IO.StringReader read = new StringReader(xmlOfAnObject);
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(myObject.GetType());
System.Xml.XmlReader reader = new XmlTextReader(read);
try
{
myObject = (MyClass)serializer.Deserialize(reader);
return myObject;
}
catch
{
throw;
}
finally
{
reader.Close();
read.Close();
read.Dispose();
}
}

Submit this story to DotNetKicks

No comments:

Post a Comment

Post your comments/questions/feedback for this Article.

 

Latest Articles