public static string ToXml<T>(this T o) where T : new() { string retVal; using (var ms = new MemoryStream()) { var xs = new XmlSerializer(typeof (T)); xs.Serialize(ms, o); ms.Flush(); ms.Position = 0; var sr = new StreamReader(ms); retVal = sr.ReadToEnd(); } return retVal; }