Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Updated Exception Handling for Collection<T> #23290

Merged
merged 5 commits into from
Mar 22, 2019
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public T this[int index]
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
}

if (index < 0 || index >= items.Count)
if ((uint)index >= (uint)items.Count)
{
ThrowHelper.ThrowArgumentOutOfRange_IndexException();
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public void Insert(int index, T item)
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
}

if (index < 0 || index > items.Count)
if ((uint)index > (uint)items.Count)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
}
Expand All @@ -125,12 +125,12 @@ public void InsertRange(int index, IEnumerable<T> collection)

if (collection == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list);
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
}

if ((uint)index > (uint)items.Count)
SkyeHoefling marked this conversation as resolved.
Show resolved Hide resolved
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index);
SkyeHoefling marked this conversation as resolved.
Show resolved Hide resolved
}

InsertItemsRange(index, collection);
Expand Down Expand Up @@ -198,7 +198,7 @@ public void ReplaceRange(int index, int count, IEnumerable<T> collection)

if (collection == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list);
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
}

ReplaceItemsRange(index, count, collection);
Expand All @@ -211,7 +211,7 @@ public void RemoveAt(int index)
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
}

if (index < 0 || index >= items.Count)
if ((uint)index >= (uint)items.Count)
{
ThrowHelper.ThrowArgumentOutOfRange_IndexException();
}
Expand Down