Created
February 17, 2012 15:17
-
-
Save pcibraro/1853986 to your computer and use it in GitHub Desktop.
DisposableEnumerable
This file contains hidden or 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
| public class DisposableEnumerable<T> : IEnumerable<T> | |
| { | |
| IEnumerable<T> source; | |
| public DisposableEnumerable(IEnumerable<T> source) | |
| { | |
| this.source = source; | |
| } | |
| public IEnumerator<T> GetEnumerator() | |
| { | |
| Console.WriteLine("Begin Section"); | |
| return new DisposableEnumerator<T>(this.source.GetEnumerator()); | |
| } | |
| System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() | |
| { | |
| Console.WriteLine("Begin Section"); | |
| return new DisposableEnumerator<T>(this.source.GetEnumerator()); | |
| } | |
| } | |
| public class DisposableEnumerator<T> : IEnumerator<T> | |
| { | |
| IEnumerator<T> source; | |
| public DisposableEnumerator(IEnumerator<T> source) | |
| { | |
| this.source = source; | |
| } | |
| public T Current | |
| { | |
| get { return this.source.Current; } | |
| } | |
| public void Dispose() | |
| { | |
| Console.WriteLine("End section"); | |
| this.source.Dispose(); | |
| } | |
| object System.Collections.IEnumerator.Current | |
| { | |
| get { return this.source.Current; } | |
| } | |
| public bool MoveNext() | |
| { | |
| return this.source.MoveNext(); | |
| } | |
| public void Reset() | |
| { | |
| this.source.Reset(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment