Skip to content

Commit 8be3d6a

Browse files
committed
Throw the correct exception type
1 parent 0d0f99d commit 8be3d6a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

DictionaryList/DictionaryList.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ public TValue this[int index]
8080
}
8181
set
8282
{
83+
if ((uint)index >= (uint)_list.Count)
84+
{
85+
// out of range!
86+
ThrowHelper.ThrowArgumentOutOfRangeException(index);
87+
}
8388
if (!_issetLookup[index])
8489
{
8590
// adding items during iteration is not allowed!

DictionaryList/ThrowHelper.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ public static void ThrowBadEnumerationException()
1010
{
1111
throw new InvalidOperationException("Collection was modified; enumeration operation may not execute.");
1212
}
13+
14+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
15+
public static void ThrowArgumentOutOfRangeException(int index)
16+
{
17+
throw new ArgumentOutOfRangeException(nameof(index));
18+
}
1319
}
1420
}

0 commit comments

Comments
 (0)