Serialize

  • Thread starter Thread starter David
  • Start date Start date
D

David

Is it possible to "Serialize" a class to xml into a string or XmlDocument
without having to create a disk file?

Thanks in advance.
 
Sure:
public string XmlSerialize()
{
XmlSerializer mySerializer = new XmlSerializer(this.GetType());
MemoryStream ms = new MemoryStream();
mySerializer.Serialize(ms, this);
ms.Position = 0;
StreamReader sr = new StreamReader(ms);
return sr.ReadToEnd();
}

And this is nice and generic.
 
XmlSerializer.Serialize() has overloads that take streams and such. Is that
what you are talking about?
 
Back
Top