Пример #1
0
        // [ResourceConsumption(ResourceScope.Machine)]
        // [ResourceExposure(ResourceScope.Machine)]
        internal XmlWriter CreateWriter(string outputFileName)
        {
            if (outputFileName == null)
            {
                throw new ArgumentNullException("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);

                // create writer
                return(newSettings.CreateWriter(fs));
            }
            catch
            {
                if (fs != null)
                {
                    fs.Close();
                }
                throw;
            }
        }
Пример #2
0
        //-----------------------------------------------
        // Constructors
        //-----------------------------------------------

        private XmlAutoDetectWriter(XmlWriterSettings writerSettings)
        {
            Debug.Assert(writerSettings.OutputMethod == XmlOutputMethod.AutoDetect);

            _writerSettings          = (XmlWriterSettings)writerSettings.Clone();
            _writerSettings.ReadOnly = true;

            // Start caching all events
            _eventCache = new XmlEventCache(string.Empty, true);
        }