mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Add more CollectionExtension methods (#4910)
Maybe array.resize is bad for sandbox coin, in which case I'd also settle for changing it to a list instead.
This commit is contained in:
@@ -8,9 +8,27 @@ namespace Robust.Shared.Utility
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Ensures that the specified array has the specified length.
|
||||
/// </summary>
|
||||
public static void EnsureLength<T>(ref T[] array, int length)
|
||||
{
|
||||
if (array.Length > length)
|
||||
return;
|
||||
|
||||
Array.Resize(ref array, length);
|
||||
}
|
||||
|
||||
public static IList<T> Clone<T>(this IList<T> listToClone) where T : ICloneable
|
||||
{
|
||||
return listToClone.Select(item => (T)item.Clone()).ToList();
|
||||
var clone = new List<T>(listToClone.Count);
|
||||
|
||||
foreach (var value in listToClone)
|
||||
{
|
||||
clone.Add((T) value.Clone());
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user