Skip to content

Instantly share code, notes, and snippets.

@jjasonclark
Created August 25, 2013 17:49
Show Gist options
  • Save jjasonclark/6335259 to your computer and use it in GitHub Desktop.
Save jjasonclark/6335259 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
namespace fixkeypath
{
class TextReadLineIterator : IDisposable, IEnumerable<string>
{
public TextReadLineIterator(TextReader InputFile)
{
this.inputReader = InputFile;
}
private TextReader inputReader;
#region IEnumerable<string> Members
public IEnumerator<string> GetEnumerator()
{
while (true)
{
string nextLine = this.inputReader.ReadLine();
if (null == nextLine) // Null on end of file
{
break;
}
yield return nextLine;
}
}
#endregion
#region IEnumerable Members
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
#region IDisposable Members
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~TextReadLineIterator()
{
Dispose(false);
}
private void Dispose(bool Disposing)
{
if (Disposing)
{
if (null != this.inputReader)
{
this.inputReader.Close();
this.inputReader = null;
}
}
else
{
//Nothing here yet
}
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment