Close() public méthode

See XmlReader.Close
public Close ( ) : void
Résultat void
 /// <summary>
 /// Creates acquired infoset.
 /// </summary>
 /// <param name="reader">Source reader</param>
 private string CreateAcquiredInfoset(XmlReader reader)
 {
     //TODO: Try to stream out this stuff
     XIncludingReader xir = new XIncludingReader(reader);
     xir.XmlResolver = this._xmlResolver;
     StringWriter sw = new StringWriter();
     XmlTextWriter w = new XmlTextWriter(sw);
     try
     {
         while (xir.Read())
             w.WriteNode(xir, false);
     }
     finally
     {
         if (xir != null)
             xir.Close();
         if (w != null)
             w.Close();
     }
     return sw.ToString();
 }
        /// <summary>
        /// Utility method for running tests.
        /// </summary>        
        public static void RunAndCompare(string source, string result, bool textAsCDATA, XmlResolver resolver) 
        {                                 
            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true;                  
            XIncludingReader xir = new XIncludingReader(source);
            if (resolver != null)
                xir.XmlResolver = resolver;
            xir.ExposeTextInclusionsAsCDATA = textAsCDATA;            
//            while (xir.Read()) 
//            {
//                Console.WriteLine("{0} | {1} | {2} | {3}", xir.NodeType, xir.Name, xir.Value, xir.IsEmptyElement);                
//            }
//            throw new Exception();
            try 
            {
                doc.Load(xir);
            } 
            catch (Exception e)
            {
                xir.Close();
                throw e;
            }
            xir.Close();
            XmlReaderSettings s = new XmlReaderSettings();
            s.ProhibitDtd = false;
            s.IgnoreWhitespace = true;           
            XmlReader r1 = XmlReader.Create(new StringReader(doc.OuterXml), s, doc.BaseURI);                        
            XmlReader r2 = XmlReader.Create(result, s);                        
            try 
            {
                while (r1.Read()) 
                {
                    Assert.IsTrue(r2.Read()); 
                    while (r1.NodeType == XmlNodeType.XmlDeclaration ||
                        r1.NodeType == XmlNodeType.Whitespace)
                        r1.Read();
                    while (r2.NodeType == XmlNodeType.XmlDeclaration ||
                        r2.NodeType == XmlNodeType.Whitespace)
                        r2.Read();
                    Assert.AreEqual(r1.XmlLang, r2.XmlLang);
                    switch (r1.NodeType) 
                    {
                        case XmlNodeType.Attribute:
                            Assert.AreEqual(r2.NodeType, XmlNodeType.Attribute);
                            Assert.AreEqual(r1.Name, r2.Name);
                            Assert.AreEqual(r1.LocalName, r2.LocalName);
                            Assert.AreEqual(r1.NamespaceURI, r2.NamespaceURI);
                            Assert.AreEqual(r1.Value, r2.Value);
                            break;                   
                        case XmlNodeType.CDATA:
                            Assert.IsTrue(r2.NodeType == XmlNodeType.CDATA || r2.NodeType == XmlNodeType.Text);
                            Assert.AreEqual(r1.Value, r2.Value);
                            break;
                        case XmlNodeType.Comment:
                            Assert.AreEqual(r2.NodeType, XmlNodeType.Comment);
                            Assert.AreEqual(r1.Value, r2.Value);
                            break;
                        case XmlNodeType.DocumentType:
                            Assert.AreEqual(r2.NodeType, XmlNodeType.DocumentType);
                            Assert.AreEqual(r1.Name, r2.Name);                        
                            //Ok, don't compare DTD content
                            //Assert.AreEqual(r1.Value, r2.Value);
                            break;
                        case XmlNodeType.Element:
                            Assert.AreEqual(r2.NodeType, XmlNodeType.Element);
                            Assert.AreEqual(r1.Name, r2.Name);
                            Assert.AreEqual(r1.LocalName, r2.LocalName);
                            Assert.AreEqual(r1.NamespaceURI, r2.NamespaceURI);
                            Assert.AreEqual(r1.Value, r2.Value);
                            break;
                        case XmlNodeType.Entity:
                            Assert.AreEqual(r2.NodeType, XmlNodeType.Entity);
                            Assert.AreEqual(r1.Name, r2.Name);
                            Assert.AreEqual(r1.Value, r2.Value);
                            break;
                        case XmlNodeType.EndElement:
                            Assert.AreEqual(r2.NodeType, XmlNodeType.EndElement);                        
                            break;
                        case XmlNodeType.EntityReference:
                            Assert.AreEqual(r2.NodeType, XmlNodeType.EntityReference);
                            Assert.AreEqual(r1.Name, r2.Name);
                            Assert.AreEqual(r1.Value, r2.Value);
                            break;
                        case XmlNodeType.Notation:
                            Assert.AreEqual(r2.NodeType, XmlNodeType.Notation);
                            Assert.AreEqual(r1.Name, r2.Name);
                            Assert.AreEqual(r1.Value, r2.Value);
                            break;
                        case XmlNodeType.ProcessingInstruction:
                            Assert.AreEqual(r2.NodeType, XmlNodeType.ProcessingInstruction);
                            Assert.AreEqual(r1.Name, r2.Name);
                            Assert.AreEqual(r1.Value, r2.Value);
                            break;
                        case XmlNodeType.SignificantWhitespace:
                            Assert.AreEqual(r2.NodeType, XmlNodeType.SignificantWhitespace);
                            Assert.AreEqual(r1.Value, r2.Value);
                            break;
                        case XmlNodeType.Text:
                            Assert.IsTrue(r2.NodeType == XmlNodeType.CDATA || r2.NodeType == XmlNodeType.Text);
                            Assert.AreEqual(r1.Value.Replace("\r\n", "\n").Replace("\r", "").Trim(), r2.Value.Replace("\r\n", "\n").Replace("\r", "").Trim());
                            break;                    
                        default:
                            break;
                    }                     
                }
                Assert.IsFalse(r2.Read());
                Assert.IsTrue(r1.ReadState == ReadState.EndOfFile || r1.ReadState == ReadState.Closed);
                Assert.IsTrue(r2.ReadState == ReadState.EndOfFile || r2.ReadState == ReadState.Closed);
            } 
            catch(Exception e) 
            {
                r1.Close();
                r1 = null;
                r2.Close();
                r2 = null;
                ReportResults(result, doc);
                throw e;
            }
            finally 
            {                
                if (r1 != null)
                    r1.Close();
                if (r2 != null)
                    r2.Close();
            }
            ReportResults(result, doc);
        }    
 /// <summary>
 /// Creates acquired infoset.
 /// </summary>        
 private string CreateAcquiredInfoset(Uri includeLocation)
 {
     if (_cache == null)
         _cache = new Dictionary<string, WeakReference>();
     WeakReference wr;
     if (_cache.TryGetValue(includeLocation.AbsoluteUri, out wr) && wr.IsAlive)
     {
         return (string)wr.Target;
     }
     else
     {
         //Not cached or GCollected
         WebResponse wRes;
         Stream stream = GetResource(includeLocation.AbsoluteUri,
             _reader.GetAttribute(_keywords.Accept),
             _reader.GetAttribute(_keywords.AcceptLanguage), out wRes);
         XIncludingReader xir = new XIncludingReader(wRes.ResponseUri.AbsoluteUri, stream, _nameTable);
         xir.WhitespaceHandling = _whiteSpaceHandling;
         StringWriter sw = new StringWriter();
         XmlTextWriter w = new XmlTextWriter(sw);
         try
         {
             while (xir.Read())
                 w.WriteNode(xir, false);
         }
         finally
         {
             if (xir != null)
                 xir.Close();
             if (w != null)
                 w.Close();
         }
         string content = sw.ToString();
         lock (_cache)
         {
             if (!_cache.ContainsKey(includeLocation.AbsoluteUri))
                 _cache.Add(includeLocation.AbsoluteUri, new WeakReference(content));
         }
         return content;
     }
 }
        public void InnerXmlTest() 
        {
			XIncludingReader xir = new XIncludingReader("../../XInclude/tests/document.xml");
            xir.MoveToContent();
            string innerXml = xir.ReadInnerXml();
            xir.Close();
			xir = new XIncludingReader("../../XInclude/tests/document.xml");
            xir.MoveToContent();
            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true;
            doc.Load(xir);            
            string innerXml2 = doc.DocumentElement.InnerXml;
            Assert.AreEqual(innerXml, innerXml2);
        }        
        public void TestXPointerIndentationBug()
        {

            XmlUrlResolver resolver = new XmlUrlResolver();
            resolver.Credentials = CredentialCache.DefaultCredentials;
            XsltSettings xsltSettings = new XsltSettings();
            xsltSettings.EnableDocumentFunction = true;
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ProhibitDtd = false;
            XmlReader reader = XmlReader.Create("../../XInclude/tests/Transform.xsl", settings);
            XIncludingReader xInputReader = new XIncludingReader("../../XInclude/tests/FileA.xml");
            try
            {
                MvpXslTransform processor = new MvpXslTransform(false);
                processor.Load(reader, xsltSettings, resolver);                
                //xInputReader.XmlResolver = new XMLBase();
                XmlDocument xInputDoc = new XmlDocument();
                xInputDoc.Load(xInputReader);
                XmlInput xInput = new XmlInput(xInputDoc);
                StringWriter stringW = new StringWriter();
                XmlOutput xOutput = new XmlOutput(stringW);
                processor.Transform(xInput, null, xOutput);
                processor.TemporaryFiles.Delete();
                Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?>NodeA Content", stringW.ToString());
            }
            finally
            {
                 reader.Close();
                 xInputReader.Close();
            }
        }
        public void TwoFallbacks() 
        {
			XIncludingReader xir = new XIncludingReader("../../XInclude/tests/twofallbacks.xml");
            while (xir.Read());
            xir.Close();
        }             
        public void UnknownParseAttribute() 
        {
			XIncludingReader xir = new XIncludingReader("../../XInclude/tests/unknownparseattr.xml");
            while (xir.Read());
            xir.Close();
        }     
        public void FallbackNotChildOfInclude() 
        {
			XIncludingReader xir = new XIncludingReader("../../XInclude/tests/fallbacknotchildinclude.xml");
            while (xir.Read());
            xir.Close();
        }     
        public void IncludeChildOfInclude() 
        {
			XIncludingReader xir = new XIncludingReader("../../XInclude/tests/includechildofinclude.xml");
            while (xir.Read());
            xir.Close();
        }
        public void NoHrefAndNoXPointerAttributes() 
        {
			XIncludingReader xir = new XIncludingReader("../../XInclude/tests/nohref.xml");
            while (xir.Read());
            xir.Close();
        }