public override bool Read()
 {
     bool flag = this.xmlReader.Read();
     if (this.xmlReader.NodeType == XmlNodeType.Element)
     {
         XopIncludeReader reader = null;
         if (this.xmlReader.IsStartElement(MtomGlobals.XopIncludeLocalName, MtomGlobals.XopIncludeNamespace))
         {
             string uri = null;
             while (this.xmlReader.MoveToNextAttribute())
             {
                 if ((this.xmlReader.LocalName == MtomGlobals.XopIncludeHrefLocalName) && (this.xmlReader.NamespaceURI == MtomGlobals.XopIncludeHrefNamespace))
                 {
                     uri = this.xmlReader.Value;
                 }
                 else if (this.xmlReader.NamespaceURI == MtomGlobals.XopIncludeNamespace)
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("MtomXopIncludeInvalidXopAttributes", new object[] { this.xmlReader.LocalName, MtomGlobals.XopIncludeNamespace })));
                 }
             }
             if (uri == null)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("MtomXopIncludeHrefNotSpecified", new object[] { MtomGlobals.XopIncludeHrefLocalName })));
             }
             MimePart part = this.ReadMimePart(uri);
             this.CheckContentTransferEncodingOnBinaryPart(part.Headers.ContentTransferEncoding);
             this.part = part;
             reader = new XopIncludeReader(part, this.xmlReader);
             reader.Read();
             this.xmlReader.MoveToElement();
             if (this.xmlReader.IsEmptyElement)
             {
                 this.xmlReader.Read();
             }
             else
             {
                 int depth = this.xmlReader.Depth;
                 this.xmlReader.ReadStartElement();
                 while (this.xmlReader.Depth > depth)
                 {
                     if (this.xmlReader.IsStartElement() && (this.xmlReader.NamespaceURI == MtomGlobals.XopIncludeNamespace))
                     {
                         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("MtomXopIncludeInvalidXopElement", new object[] { this.xmlReader.LocalName, MtomGlobals.XopIncludeNamespace })));
                     }
                     this.xmlReader.Skip();
                 }
                 this.xmlReader.ReadEndElement();
             }
         }
         if (reader != null)
         {
             this.xmlReader.MoveToContent();
             this.infosetReader = this.xmlReader;
             this.xmlReader = reader;
             reader = null;
         }
     }
     if ((this.xmlReader.ReadState == System.Xml.ReadState.EndOfFile) && (this.infosetReader != null))
     {
         if (!flag)
         {
             flag = this.infosetReader.Read();
         }
         this.part.Release(this.maxBufferSize, ref this.bufferRemaining);
         this.xmlReader = this.infosetReader;
         this.infosetReader = null;
     }
     return flag;
 }
        public override bool Read()
        {
            bool retVal = xmlReader.Read();

            if (xmlReader.NodeType == XmlNodeType.Element)
            {
                XopIncludeReader binaryDataReader = null;
                if (xmlReader.IsStartElement(MtomGlobals.XopIncludeLocalName, MtomGlobals.XopIncludeNamespace))
                {
                    string uri = null;
                    while (xmlReader.MoveToNextAttribute())
                    {
                        if (xmlReader.LocalName == MtomGlobals.XopIncludeHrefLocalName && xmlReader.NamespaceURI == MtomGlobals.XopIncludeHrefNamespace)
                            uri = xmlReader.Value;
                        else if (xmlReader.NamespaceURI == MtomGlobals.XopIncludeNamespace)
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.MtomXopIncludeInvalidXopAttributes, xmlReader.LocalName, MtomGlobals.XopIncludeNamespace)));
                    }
                    if (uri == null)
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.MtomXopIncludeHrefNotSpecified, MtomGlobals.XopIncludeHrefLocalName)));

                    MimePart mimePart = ReadMimePart(uri);

                    CheckContentTransferEncodingOnBinaryPart(mimePart.Headers.ContentTransferEncoding);

                    this.part = mimePart;
                    binaryDataReader = new XopIncludeReader(mimePart, xmlReader);
                    binaryDataReader.Read();

                    xmlReader.MoveToElement();
                    if (xmlReader.IsEmptyElement)
                    {
                        xmlReader.Read();
                    }
                    else
                    {
                        int xopDepth = xmlReader.Depth;
                        xmlReader.ReadStartElement();

                        while (xmlReader.Depth > xopDepth)
                        {
                            if (xmlReader.IsStartElement() && xmlReader.NamespaceURI == MtomGlobals.XopIncludeNamespace)
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.MtomXopIncludeInvalidXopElement, xmlReader.LocalName, MtomGlobals.XopIncludeNamespace)));

                            xmlReader.Skip();
                        }

                        xmlReader.ReadEndElement();
                    }
                }

                if (binaryDataReader != null)
                {
                    this.xmlReader.MoveToContent();
                    this.infosetReader = this.xmlReader;
                    this.xmlReader = binaryDataReader;
                    binaryDataReader = null;
                }
            }

            if (xmlReader.ReadState == ReadState.EndOfFile && infosetReader != null)
            {
                // Read past the containing EndElement if necessary
                if (!retVal)
                    retVal = infosetReader.Read();

                this.part.Release(this.maxBufferSize, ref this.bufferRemaining);
                xmlReader = infosetReader;
                infosetReader = null;
            }

            return retVal;
        }