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

Commit

Permalink
Updated Exception Handling for Collection<T> (dotnet/coreclr#23290)
Browse files Browse the repository at this point in the history
* Updated Argument Helper param from list->collection since the parameter name is collection

* Updated exception message to use an out of range exception that doesn't explicitly reference a list

* Simplified if statements that verify if the index is out of range

* Updated if logic to be simplified using (uint)

* Updated exception handling to throw ThrowHelper.ThrowArgumentOutOfRange_IndexException() when the ExceptionArgument was 'Index'

Signed-off-by: dotnet-bot <[email protected]>
  • Loading branch information
Andrew Hoefling authored and jkotas committed Mar 22, 2019
1 parent be7db25 commit c797d0c
Showing 1 changed file with 7 additions and 7 deletions.
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,9 +108,9 @@ 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);
ThrowHelper.ThrowArgumentOutOfRange_IndexException();
}

InsertItem(index, item);
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)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
ThrowHelper.ThrowArgumentOutOfRange_IndexException();
}

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

0 comments on commit c797d0c

Please sign in to comment.