示例#1
0
 protected override void EndProcessing()
 {
     if (this._serializer != null)
     {
         this._serializer.Done();
         this._serializer = null;
     }
     if (this._as.Equals("Stream", StringComparison.OrdinalIgnoreCase))
     {
         base.WriteObject("</Objects>");
     }
     else
     {
         this._ms.Position = 0L;
         if (this._as.Equals("Document", StringComparison.OrdinalIgnoreCase))
         {
             XmlDocument sendToPipeline = new XmlDocument();
             sendToPipeline.Load(this._ms);
             base.WriteObject(sendToPipeline);
         }
         else if (this._as.Equals("String", StringComparison.OrdinalIgnoreCase))
         {
             string str = new StreamReader(this._ms).ReadToEnd();
             base.WriteObject(str);
         }
     }
     this.CleanUp();
 }
示例#2
0
 private void CreateMemoryStream()
 {
     this._ms = new MemoryStream();
     this._xw = new XmlTextWriter(this._ms, null);
     this._xw.Formatting = Formatting.Indented;
     if (!this._as.Equals("Stream", StringComparison.OrdinalIgnoreCase))
     {
         this._xw.WriteStartDocument();
     }
     if (this._depth == 0)
     {
         this._serializer = new CustomSerialization(this._xw, this._notypeinformation);
     }
     else
     {
         this._serializer = new CustomSerialization(this._xw, this._notypeinformation, this._depth);
     }
 }
示例#3
0
 protected override void ProcessRecord()
 {
     if (this._as.Equals("Stream", StringComparison.OrdinalIgnoreCase))
     {
         this.CreateMemoryStream();
         if (this._serializer != null)
         {
             this._serializer.SerializeAsStream(this._object);
         }
         if (this._serializer != null)
         {
             this._serializer.DoneAsStream();
             this._serializer = null;
         }
         this._ms.Position = 0L;
         string sendToPipeline = new StreamReader(this._ms).ReadToEnd();
         base.WriteObject(sendToPipeline);
         this.CleanUp();
     }
     else if (this._serializer != null)
     {
         this._serializer.Serialize(this._object);
     }
 }
示例#4
0
        private void CreateMemoryStream()
        {
            // Memory Stream
            _ms = new MemoryStream();

            // We use XmlTextWriter originally:
            //     _xw = new XmlTextWriter(_ms, null);
            //     _xw.Formatting = Formatting.Indented;
            // This implies the following settings:
            //  - Encoding is null -> use the default encoding 'UTF-8' when creating the writer from the stream;
            //  - XmlTextWriter closes the underlying stream / writer when 'Close/Dispose' is called on it;
            //  - Use the default indentation setting -- two space characters.
            //
            // We configure the same settings in XmlWriterSettings when refactoring this code to use XmlWriter:
            //  - The default encoding used by XmlWriterSettings is 'UTF-8', but we call it out explicitly anyway;
            //  - Set CloseOutput to true;
            //  - Set Indent to true, and by default, IndentChars is two space characters.
            //
            // We use XmlWriterSettings.OmitXmlDeclaration instead of XmlWriter.WriteStartDocument because the
            // xml writer created by calling XmlWriter.Create(Stream, XmlWriterSettings) will write out the xml
            // declaration even without calling WriteStartDocument().

            var xmlSettings = new XmlWriterSettings();
            xmlSettings.Encoding = Encoding.UTF8;
            xmlSettings.CloseOutput = true;
            xmlSettings.Indent = true;

            if (As.Equals("Stream", StringComparison.OrdinalIgnoreCase))
            {
                // Omit xml declaration in this case because we will write out the declaration string in BeginProcess.
                xmlSettings.OmitXmlDeclaration = true;
            }

            _xw = XmlWriter.Create(_ms, xmlSettings);

            if (Depth == 0)
            {
                _serializer = new CustomSerialization(_xw, _notypeinformation);
            }
            else
            {
                _serializer = new CustomSerialization(_xw, _notypeinformation, Depth);
            }
        }