public override void Save(string filename) { using (var fileStream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write)) { XmlWriter xmlWriter = null; try { if (PreserveWhitespace) { XmlFormatter.Format(this); xmlWriter = new XmlAttributePreservingWriter(fileStream, TextEncoding); } else { xmlWriter = new XmlTextWriter(fileStream, TextEncoding) { Formatting = Formatting.Indented }; } WriteTo(xmlWriter); } finally { if (xmlWriter != null) { xmlWriter.Flush(); xmlWriter.Close(); xmlWriter.Dispose(); xmlWriter = null; } } } }
public override void Save(Stream outStream) { XmlWriter xmlWriter = null; try { if (PreserveWhitespace) { XmlFormatter.Format(this); xmlWriter = new XmlAttributePreservingWriter(outStream, TextEncoding); } else { xmlWriter = new XmlTextWriter(outStream, TextEncoding) { Formatting = Formatting.Indented }; } WriteTo(xmlWriter); } finally { if (xmlWriter != null) { xmlWriter.Flush(); xmlWriter.Close(); xmlWriter.Dispose(); xmlWriter = null; } } }