using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace VocaluxeLib
{
public static class Extensions
{
///
/// Resizes the given list to the given size. Removes elements or adds default values
///
///
///
///
///
public static void Resize(this List list, int size, T defaultValue = default(T))
{
int curSize = list.Count;
if (size < curSize)
list.RemoveRange(size, curSize - size);
else if (size > curSize)
list.AddRange(Enumerable.Repeat(defaultValue, size - curSize));
}
///
/// Makes the list at least the given size adding the given default values.
///
///
///
///
///
public static void EnsureSize(this List list, int size, T defaultValue)
{
int curSize = list.Count;
if (size > curSize)
list.AddRange(Enumerable.Repeat(defaultValue, size - curSize));
}
///
/// Makes the list at least the given size adding a new instance of T
///
///
///
///
public static void EnsureSize(this List list, int size) where T : new()
{
if (size > list.Count)
list.Add(new T());
}
}
}