Created
August 25, 2013 17:49
-
-
Save jjasonclark/6335259 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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