internal XmlWriter CreateWriter(string outputFileName) { if (outputFileName == null) { throw new ArgumentNullException(nameof(outputFileName)); } // need to clone the settigns so that we can set CloseOutput to true to make sure the stream gets closed in the end XmlWriterSettings newSettings = this; if (!newSettings.CloseOutput) { newSettings = newSettings.Clone(); newSettings.CloseOutput = true; } FileStream fs = null; try { // open file stream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.Write, FileShare.Read, 0x1000, _useAsync); // create writer return(newSettings.CreateWriter(fs)); } catch { if (fs != null) { fs.Dispose(); } throw; } }
internal XmlWriter CreateWriter(string outputFileName) { XmlWriter writer; if (outputFileName == null) { throw new ArgumentNullException("outputFileName"); } XmlWriterSettings settings = this; if (!settings.CloseOutput) { settings = settings.Clone(); settings.CloseOutput = true; } FileStream output = null; try { output = new FileStream(outputFileName, FileMode.Create, FileAccess.Write, FileShare.Read); writer = settings.CreateWriter(output); } catch { if (output != null) { output.Close(); } throw; } return(writer); }
// Creates an XmlWriter for writing into the provided StringBuilder with the specified settings. public static XmlWriter Create(StringBuilder output, XmlWriterSettings settings) { if (output == null) { throw new ArgumentNullException(nameof(output)); } settings ??= XmlWriterSettings.s_defaultWriterSettings; return(settings.CreateWriter(new StringWriter(output, CultureInfo.InvariantCulture))); }
// Creates an XmlWriter wrapped around the provided XmlWriter with the specified settings. public static XmlWriter Create(XmlWriter output, XmlWriterSettings settings) { settings ??= XmlWriterSettings.s_defaultWriterSettings; return(settings.CreateWriter(output)); }
// Creates an XmlWriter for writing into the provided file with the specified settings. public static XmlWriter Create(string outputFileName, XmlWriterSettings settings) { settings ??= XmlWriterSettings.s_defaultWriterSettings; return(settings.CreateWriter(outputFileName)); }