public static string SerializeObject<T>(T obj)
{
try
{
string xmlString = null;
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xs = new XmlSerializer(typeof(T));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
xs.Serialize(xmlTextWriter, obj);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
xmlString = UTF8ByteArrayToString(memoryStream.ToArray()); return xmlString;
}
catch
{
return string.Empty;
}
}
this is from - http://geekswithblogs.net/paulwhitblog/archive/2007/07/20/114076.aspx
Is there a way to write this where the memoryStream object doesn't need to be reassigned? Shouldn't it be disposed (wrapped in a using block)? What is the memoryStream used then reassigned?