Monthly Archives: June 2012

Convert Non-Generic IEnumerator to IEnumerable

[code lang=”csharp”]
/// <summary>
/// Converts a Non-Generic IEnumerator to IEnumerable
/// </summary>
/// <param name="enumerator"></param>
/// <returns></returns>
public static IEnumerable ToIEnumerable(this IEnumerator enumerator) {
while (enumerator.MoveNext()) {
yield return enumerator.Current;
}
yield break;
}
[/code]