forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListExtensions.cs
More file actions
44 lines (43 loc) · 1.17 KB
/
ListExtensions.cs
File metadata and controls
44 lines (43 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
namespace Simple.Data.Ado
{
using System;
using System.Collections.Generic;
internal static class ListExtensions
{
public static void SetWithBuffer<T>(this List<T> list, int index, T value)
{
if (list.Capacity > index)
{
while (list.Count < index)
{
list.Add(default(T));
}
if (list.Count == index)
{
list.Add(value);
}
else
{
list[index] = value;
}
}
else
{
if (list.Capacity < index)
{
int newCapacity = list.Capacity;
while (newCapacity < index)
{
newCapacity *= 2;
}
list.Capacity = newCapacity;
}
while (list.Count < index)
{
list.Add(default(T));
}
list.Add(value);
}
}
}
}