diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-08-09 15:59:26 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-09 15:59:26 -0400 |
| commit | c2996935c8a873662e6d301f139c88df8a542ed2 (patch) | |
| tree | cf405f91e893fe6a3fc20dfa1622f027666d4848 /MediaBrowser.Model/Extensions/LinqExtensions.cs | |
| parent | ab834f8fdffb64b562ece0512a53f361c62f7f6f (diff) | |
| parent | 7a74c705e584774534b74e11c1ab86144cb454c6 (diff) | |
Merge pull request #2800 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Model/Extensions/LinqExtensions.cs')
| -rw-r--r-- | MediaBrowser.Model/Extensions/LinqExtensions.cs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/MediaBrowser.Model/Extensions/LinqExtensions.cs b/MediaBrowser.Model/Extensions/LinqExtensions.cs index 6b2bdb4c7..43e4a66cd 100644 --- a/MediaBrowser.Model/Extensions/LinqExtensions.cs +++ b/MediaBrowser.Model/Extensions/LinqExtensions.cs @@ -42,6 +42,32 @@ namespace MediaBrowser.Model.Extensions return source.DistinctBy(keySelector, null); } + public static TSource[] ToArray<TSource>(this IEnumerable<TSource> source, int count) + { + if (source == null) throw new ArgumentNullException("source"); + if (count < 0) throw new ArgumentOutOfRangeException("count"); + var array = new TSource[count]; + int i = 0; + foreach (var item in source) + { + array[i++] = item; + } + return array; + } + + public static List<TSource> ToList<TSource>(this IEnumerable<TSource> source, int count) + { + if (source == null) throw new ArgumentNullException("source"); + if (count < 0) throw new ArgumentOutOfRangeException("count"); + var array = new List<TSource>(count); + int i = 0; + foreach (var item in source) + { + array[i++] = item; + } + return array; + } + /// <summary> /// Returns all distinct elements of the given source, where "distinctness" /// is determined via a projection and the specified comparer for the projected type. |
