コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        // 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)));
        }
コード例 #4
0
 // 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));
 }
コード例 #5
0
 // 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));
 }