Enumerating Collections that are not inherently IEnumerable?

This code should do the trick public static class Extensions { public static IEnumerable<T> GetRecursively<T>(this IEnumerable collection, Func<T, IEnumerable> selector) { foreach (var item in collection.OfType<T>()) { yield return item; IEnumerable<T> children = selector(item).GetRecursively(selector); foreach (var child in children) { yield return child; } } } } Here’s an example of how to use it … Read more