From 01adae878ded6fe51f6def1370255d816ab42d78 Mon Sep 17 00:00:00 2001 From: Andrew Hoefling Date: Thu, 21 Mar 2019 22:23:53 -0400 Subject: [PATCH] Updated Exception Handling for Collection (#23290) * 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' --- .../shared/System/Collections/ObjectModel/Collection.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs b/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs index 5d6c9c9..4898c0c 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs @@ -49,7 +49,7 @@ namespace System.Collections.ObjectModel ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection); } - if (index < 0 || index >= items.Count) + if ((uint)index >= (uint)items.Count) { ThrowHelper.ThrowArgumentOutOfRange_IndexException(); } @@ -108,9 +108,9 @@ namespace System.Collections.ObjectModel 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); @@ -125,12 +125,12 @@ namespace System.Collections.ObjectModel 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); @@ -198,7 +198,7 @@ namespace System.Collections.ObjectModel if (collection == null) { - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection); } ReplaceItemsRange(index, count, collection); @@ -211,7 +211,7 @@ namespace System.Collections.ObjectModel ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection); } - if (index < 0 || index >= items.Count) + if ((uint)index >= (uint)items.Count) { ThrowHelper.ThrowArgumentOutOfRange_IndexException(); } -- 2.7.4