Serialize object to Xml string

For easy reference, this is how to serialize an object to an Xml string:

public static string SerializeToXmlString<T>(T o)
{
   XmlSerializer serializer = new XmlSerializer(typeof(T));
   StringWriter writer = new StringWriter();
   serializer.Serialize(writer, o);
   writer.Close();
   return writer.GetStringBuilder().ToString();
}

/Emil

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.