.NET – Why is XMLNodelist a one-time?

I can’t find the answer to this question.

Out of curiosity, why the XmlNodeList class implements IDisposable in .NET 4.5, but in the previous Not in the version?

The most likely reason is the same as IEnumerator< T>. IDisposable is implemented, but IEnumerator does not – early The version was written before the author thought of a situation where an implementation might need to be cleaned up, but a factory returning to such an implementation might not know such a requirement. For example, a class might accept a file name and provide a “real-time” XmlNodeList from that file; XmlList The IDisposable.Dispose method will close the underlying file. If any important user of the interface or abstract class must use the following code:

IDisposable asDispos = thing as IDisposable;
if (asDispos != null)
asDispos.Dispose();

And if many of those should not, then the thing should be possible to implement IDisposable itself, because the unconditional call to IDisposable.Dispose Know that the class that implements IDisposable is faster, instead of trying to cast the class may or may not implement IDisposable.Dispose.

I can’t find the answer to this question.

Out of curiosity, why does the XmlNodeList class implement IDisposable in .NET 4.5, but not in the previous version?

The most likely reason is the same as IEnumerator< T>. IDisposable is implemented, but IEnumerator does not – the earlier version was when the author thought of a situation where an implementation might need to be cleaned up Written before, but a factory that returns such an implementation may not know such requirements. For example, a class may accept a file name and provide a “real-time” XmlNodeList from the file; the IDisposable.Dispose method of XmlList will close the underlying file. If the interface or Any important users of abstract classes must use the following code:

IDisposable asDispos = thing as IDisposable;
if (asDispos != null)
asDispos.Dispose();

And if many of those shouldn’t, then the thing should be possible to implement IDisposable itself, because calling IDisposable.Dispose unconditionally is faster for classes known to implement IDisposable, instead of trying to force The conversion class may or may not implement IDisposable.Dispose.

Leave a Comment

Your email address will not be published.