예제 #1
0
        void Initialize()
        {
            if (this.isClosed)
                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.XmlWriterClosed)));

            if (this.initialContentTypeForRootPart != null)
            {
                if (this.initialContentTypeForMimeMessage != null)
                {
                    mimeWriter.StartPreface();
                    mimeWriter.WriteHeader(MimeGlobals.MimeVersionHeader, MimeGlobals.DefaultVersion);
                    mimeWriter.WriteHeader(MimeGlobals.ContentTypeHeader, this.initialContentTypeForMimeMessage);
                    this.initialContentTypeForMimeMessage = null;
                }

                WriteMimeHeaders(this.contentID, this.initialContentTypeForRootPart, this.isUTF8 ? MimeGlobals.Encoding8bit : MimeGlobals.EncodingBinary);

                Stream infosetContentStream = this.mimeWriter.GetContentStream();
                IXmlTextWriterInitializer initializer = writer as IXmlTextWriterInitializer;
                if (initializer == null)
                    writer = XmlDictionaryWriter.CreateTextWriter(infosetContentStream, this.encoding, this.ownsStream);
                else
                    initializer.SetOutput(infosetContentStream, this.encoding, this.ownsStream);

                this.contentID = null;
                this.initialContentTypeForRootPart = null;
            }
        }
예제 #2
0
    public static void IXmlTextReaderInitializerTest()
    {
        DataContractSerializer serializer           = new DataContractSerializer(typeof(TestData));
        MemoryStream           ms                   = new MemoryStream();
        TestData                  td                = new TestData();
        Encoding                  encoding          = Encoding.UTF8;
        XmlDictionaryWriter       textWriter        = XmlDictionaryWriter.CreateTextWriter(ms, encoding, false);
        IXmlTextWriterInitializer writerInitializer = (IXmlTextWriterInitializer)textWriter;

        writerInitializer.SetOutput(ms, encoding, false);
        serializer.WriteObject(ms, td);
        textWriter.Flush();
        byte[] xmlDoc = ms.ToArray();
        textWriter.Close();
        XmlDictionaryReader       textReader        = XmlDictionaryReader.CreateTextReader(xmlDoc, 0, xmlDoc.Length, encoding, XmlDictionaryReaderQuotas.Max, new OnXmlDictionaryReaderClose((XmlDictionaryReader reader) => { }));
        IXmlTextReaderInitializer readerInitializer = (IXmlTextReaderInitializer)textReader;

        readerInitializer.SetInput(xmlDoc, 0, xmlDoc.Length, encoding, XmlDictionaryReaderQuotas.Max, new OnXmlDictionaryReaderClose((XmlDictionaryReader reader) => { }));
        textReader.ReadContentAsObject();
        textReader.Close();
    }