So, code analysis tells me that Enumarble.Where(this ...) returns an instance of WhereListIterator<T> , which (looks) like an internal type within .NET that implements IDisposable .
Stealth does not like IDisposable to go uncontrollable, and therefore offers me to get rid of the specified instance. Obviously, I cannot get rid of the instance without doing some type checking, since Enumerable.Where(this ...) is said to return an IEnumerable<T> , which does not matter from IDisposable .
My question is this: does .NET expect me to dispose of WhereListIterator<T> , or WhereListIterator<T> iterator dispose of itself (say, after each listing). If I'm not going to get rid of it, then why is the interface implemented? This leads me to a third, slightly unrelated question: if IDisposable was implemented explicitly, would Coverity (code analysis) still think that I should handle it?
Code example:
var myList = new List<int>{ 1, 2, 3, 4 }; var evenNumbers = myList.Where(x => x % 2 == 0); foreach(var number in evenNumbers) { Console.WriteLine(number); } if(evenNumbers is IDisposable) { ((IDisposable)evenNumbers).Dispose();
source share