You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
861 B
28 lines
861 B
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Rssdp.Infrastructure
|
|
{
|
|
internal static class IEnumerableExtensions
|
|
{
|
|
public static IEnumerable<T> SelectManyRecursive<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> 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<T> EmptyIfNull<T>(this IEnumerable<T> source)
|
|
{
|
|
return source ?? Enumerable.Empty<T>();
|
|
}
|
|
}
|
|
}
|