2019-10-09 15:10:16 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-03-05 09:27:25 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace MediaBrowser.Common.Extensions
|
|
|
|
{
|
|
|
|
// The MS CollectionExtensions are only available in netcoreapp
|
|
|
|
public static class CollectionExtensions
|
|
|
|
{
|
2019-09-20 10:42:08 +00:00
|
|
|
public static TValue GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key)
|
2019-03-05 09:27:25 +00:00
|
|
|
{
|
|
|
|
dictionary.TryGetValue(key, out var ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2019-09-02 06:19:29 +00:00
|
|
|
|
2019-09-20 10:42:08 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Copies all the elements of the current collection to the specified list
|
|
|
|
/// starting at the specified destination array index. The index is specified as a 32-bit integer.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="source">The current collection that is the source of the elements.</param>
|
|
|
|
/// <param name="destination">The list that is the destination of the elements copied from the current collection.</param>
|
|
|
|
/// <param name="index">A 32-bit integer that represents the index in <c>destination</c> at which copying begins.</param>
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
public static void CopyTo<T>(this IReadOnlyList<T> source, IList<T> destination, int index = 0)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < source.Count; i++)
|
|
|
|
{
|
|
|
|
destination[index + i] = source[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-02 06:19:29 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Copies all the elements of the current collection to the specified list
|
|
|
|
/// starting at the specified destination array index. The index is specified as a 32-bit integer.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="source">The current collection that is the source of the elements.</param>
|
|
|
|
/// <param name="destination">The list that is the destination of the elements copied from the current collection.</param>
|
|
|
|
/// <param name="index">A 32-bit integer that represents the index in <c>destination</c> at which copying begins.</param>
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
public static void CopyTo<T>(this IReadOnlyCollection<T> source, IList<T> destination, int index = 0)
|
|
|
|
{
|
|
|
|
foreach (T item in source)
|
|
|
|
{
|
|
|
|
destination[index++] = item;
|
|
|
|
}
|
|
|
|
}
|
2019-03-05 09:27:25 +00:00
|
|
|
}
|
|
|
|
}
|