using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Rssdp.Infrastructure { internal static class IEnumerableExtensions { public static IEnumerable SelectManyRecursive(this IEnumerable source, Func> selector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (selector == null) throw new ArgumentNullException(nameof(selector)); return !source.Any() ? source : source.Concat( source .SelectMany(i => selector(i).EmptyIfNull()) .SelectManyRecursive(selector) ); } public static IEnumerable EmptyIfNull(this IEnumerable source) { return source ?? Enumerable.Empty(); } } }