36 lines
943 B
C#
36 lines
943 B
C#
namespace LANCommander.Extensions
|
|
{
|
|
public static class ListExtensions
|
|
{
|
|
public static void Move<T>(this List<T> list, int oldIndex, int newIndex)
|
|
{
|
|
var item = list[oldIndex];
|
|
|
|
list.RemoveAt(oldIndex);
|
|
|
|
if (newIndex > oldIndex) newIndex--;
|
|
// the actual index could have shifted due to the removal
|
|
|
|
list.Insert(newIndex, item);
|
|
}
|
|
|
|
public static void Move<T>(this List<T> list, T item, int newIndex)
|
|
{
|
|
if (item != null)
|
|
{
|
|
var oldIndex = list.IndexOf(item);
|
|
|
|
if (oldIndex > -1)
|
|
{
|
|
list.RemoveAt(oldIndex);
|
|
|
|
if (newIndex > oldIndex) newIndex--;
|
|
// the actual index could have shifted due to the removal
|
|
|
|
list.Insert(newIndex, item);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|