I have a list of strings that is being read in from a file and filtered, all of which is happening using the yield mechanisms so that it is lazy. I then need to pass this into a method which takes a TextReader.
Is there anything wrong with this method? It seems to work, but wanted to know I had missed something.
public class EnumerableReader : TextReader
{
private readonly IEnumerator<string> _enumerator;
public EnumerableReader(IEnumerable<string> lines)
{
_enumerator = lines.GetEnumerator();
}
public override string ReadLine()
{
return _enumerator.MoveNext() ? _enumerator.Current : null;
}
protected override void Dispose(bool disposing)
{
_enumerator.Dispose();
base.Dispose(disposing);
}
}