Compare Page Revisions
« Older Revision - Back to Page History - Current Revision
var myObject = new MyClass(); var xs = new XmlSerializer(myObject.GetType()); string resultXml; using (var sw = new StringWriter()) { xs.Serialize(sw, myObject); resultXml = sw.ToString(); }
public static string SerializeToXml<T>(T input) { var result = string.Empty; var xs = new XmlSerializer(typeof(T)); using (var sw = new StringWriter()) { xs.Serialize(sw, input); result = sw.ToString(); } return result; } public static T DeserializeFromXml<T>(string inputXml) { T result = default(T); var xs = new XmlSerializer(typeof(T)); using (var sr = new StringReader(inputXml)) { result = (T)xs.Deserialize(sr); sr.Close(); } return result; }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.