public void SaveToDisk(FileInfo info, object resource) { resource = resource ?? new UvMapping(); using (var writeStream = info.Open(FileMode.Create)) m_xmlArchive.Write(writeStream, (UvMapping)resource); }
public static void Main() { var students = new List <Student>(); students.Add(new Student { Name = "Alfred" }); students.Add(new Student { Name = "Ben" }); students.Add(new Student { Name = "Camila" }); students.Add(new Student { Name = "Denise" }); var alfred = students[0]; var ben = students[1]; var camila = students[2]; var denise = students[3]; alfred.AddFriend(ben); alfred.AddFriend(camila); ben.AddFriend(alfred); ben.AddFriend(denise); camila.AddFriend(alfred); camila.AddFriend(ben); camila.AddFriend(denise); denise.AddFriend(camila); var archive = new XmlArchive(typeof(List <Student>)); string xml; using (var s = new MemoryStream()) { archive.Write(s, students, "Students"); s.Position = 0; using (var reader = new StreamReader(s)) { xml = reader.ReadToEnd(); } } Console.WriteLine(xml); }
public static string SerializeObject <X>(X toSerialize) { var xmlSerializer = new XmlArchive(toSerialize.GetType()); Archive.Provider = CultureInfo.InvariantCulture; string utf8 = "";; using (var writer = new MemoryStream()) { xmlSerializer.Write(writer, toSerialize); writer.Position = 0; var reader = new StreamReader(writer); utf8 = reader.ReadToEnd(); } return(utf8); }