1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2025-02-26 08:02:56 +00:00
Radarr/src/NzbDrone.Common/IEnumerableExtensions.cs
2014-05-01 16:51:18 -07:00

26 lines
No EOL
665 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace NzbDrone.Common
{
public static class EnumerableExtensions
{
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)));
}
public static void AddIfNotNull<TSource>(this List<TSource> source, TSource item)
{
if (item == null)
{
return;
}
source.Add(item);
}
}
}