From dca78b13411db96366dddfa0d68bb6d36d28ad14 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 29 Oct 2016 18:22:20 -0400 Subject: rework dlna project --- RSSDP/IEnumerableExtensions.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 RSSDP/IEnumerableExtensions.cs (limited to 'RSSDP/IEnumerableExtensions.cs') diff --git a/RSSDP/IEnumerableExtensions.cs b/RSSDP/IEnumerableExtensions.cs new file mode 100644 index 000000000..f72073949 --- /dev/null +++ b/RSSDP/IEnumerableExtensions.cs @@ -0,0 +1,28 @@ +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("source"); + if (selector == null) throw new ArgumentNullException("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(); + } + } +} -- cgit v1.2.3