System.Xml 2.0: XmlReader is now IDisposabe

| 2 Comments | No TrackBacks

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.

Related Blog Posts

No TrackBacks

TrackBack URL: http://www.tkachenko.com/cgi-bin/mt-tb.cgi/441

2 Comments

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

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?

Leave a comment