2013-08-22 04:42:25 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace NzbDrone.Common
|
|
|
|
{
|
2013-09-19 01:09:26 +00:00
|
|
|
public static class EnumerableExtensions
|
2013-08-22 04:42:25 +00:00
|
|
|
{
|
|
|
|
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
|
|
|
{
|
|
|
|
var knownKeys = new HashSet<TKey>();
|
|
|
|
|
|
|
|
return source.Where(element => knownKeys.Add(keySelector(element)));
|
|
|
|
}
|
2014-04-30 23:39:54 +00:00
|
|
|
|
|
|
|
public static void AddIfNotNull<TSource>(this List<TSource> source, TSource item)
|
|
|
|
{
|
|
|
|
if (item == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
source.Add(item);
|
|
|
|
}
|
2013-08-22 04:42:25 +00:00
|
|
|
}
|
|
|
|
}
|