May 16, 2005

System.Xml 2.0: XmlReader is now IDisposabe

Another handy feature implemented in .NET 2.0 Beta2 is that XmlReader class now implements IDisposable interface and so can be closed automatically when using with "using" statement in C#:

using (XmlReader r = XmlReader.Create("../../source.xml"))
{
  while (r.Read())
    Console.WriteLine(r.NodeType);
}
Really handy. And implemented in literally couple of lines. It's a pity we don't have such simple but useful stuff in .NET 1.1.

May 16, 2005 2:04 PM | #System.Xml v2.0 , #XML
Comments

You mean concrete XmlReader implementations? It's XmlReader class itself who implements IDisposable, so that means all its implementations implement it too.

Posted by: Oleg Tkachenko at May 17, 2005 11:15 AM

That is great. I can't count the number of times that I've wanted that. I wonder how many XmlReader wrappers are out there implementing that?

Posted by: andy brummer at May 17, 2005 6:15 AM
Post a comment




Remember Me?