#pragma warning disable CS1591
using System;
using System.Collections.Generic;
namespace MediaBrowser.Common.Extensions
{
// The MS CollectionExtensions are only available in netcoreapp
public static class CollectionExtensions
{
private static readonly Random _rng = new Random();
///
/// Shuffles the items in a list.
///
/// The list that should get shuffled.
/// The type.
public static void Shuffle(this IList list)
{
int n = list.Count;
while (n > 1)
{
n--;
int k = _rng.Next(n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
public static TValue GetValueOrDefault(this IReadOnlyDictionary dictionary, TKey key)
{
dictionary.TryGetValue(key, out var ret);
return ret;
}
///
/// 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.
///
/// The current collection that is the source of the elements.
/// The list that is the destination of the elements copied from the current collection.
/// A 32-bit integer that represents the index in destination at which copying begins.
///
public static void CopyTo(this IReadOnlyList source, IList destination, int index = 0)
{
for (int i = 0; i < source.Count; i++)
{
destination[index + i] = source[i];
}
}
}
}