object serialization example

Tijut2k
Posted by Tijut2k under C# category on | Points: 40 | Views : 2080
private string SerializeAnObject(object obj)
{

System.Xml.XmlDocument doc;
System.Xml.Serialization.XmlSerializer serializer;
System.IO.MemoryStream stream;
doc = new XmlDocument();
serializer = new System.Xml.Serialization.XmlSerializer(obj.GetType());
stream = new System.IO.MemoryStream();
try
{
serializer.Serialize(stream, obj);
stream.Position = 0;
doc.Load(stream);
return doc.InnerXml;

}
catch
{
throw;
}
finally
{
stream.Close();
stream.Dispose();
}
}

Comments or Responses

Login to post response