summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Hoefling <andrew@hoeflingsoftware.com>2019-03-04 22:28:05 -0500
committerSantiago Fernandez Madero <safern@microsoft.com>2019-03-08 11:20:58 -0800
commit96de98c1aab0b65c0dfd667bc86e6ab14794306c (patch)
treef0c1903e0169e7d42462345d0834d93f1d318055 /src
parent69c3b0355df56fd47f98faf574e24f577f6d29c2 (diff)
downloadcoreclr-96de98c1aab0b65c0dfd667bc86e6ab14794306c.tar.gz
coreclr-96de98c1aab0b65c0dfd667bc86e6ab14794306c.tar.bz2
coreclr-96de98c1aab0b65c0dfd667bc86e6ab14794306c.zip
Added ReplaceItemsRange API and updated ReplaceRange to invoke the protected method
Diffstat (limited to 'src')
-rw-r--r--src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs16
1 files changed, 10 insertions, 6 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 4d4825a4cc..69d50fbeab 100644
--- a/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs
+++ b/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs
@@ -133,11 +133,7 @@ namespace System.Collections.ObjectModel
public void RemoveRange(int index, int count) => RemoveItemsRange(index, count);
- public void ReplaceRange(int index, int count, IEnumerable<T> collection)
- {
- RemoveItemsRange(index, count);
- InsertItemsRange(index, collection);
- }
+ public void ReplaceRange(int index, int count, IEnumerable<T> collection) => ReplaceItemsRange(index, count, collection);
public void RemoveAt(int index)
{
@@ -211,12 +207,20 @@ namespace System.Collections.ObjectModel
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
}
- for (int i = index; i < (index + count); i++)
+ int indexCount = index + count;
+ int length = indexCount > items.Count ? items.Count : indexCount;
+ for (int i = index; i < length; i++)
{
RemoveAt(index);
}
}
+ protected virtual void ReplaceItemsRange(int index, int count, IEnumerable<T> collection)
+ {
+ RemoveItemsRange(index, count);
+ InsertItemsRange(index, collection);
+ }
+
bool ICollection<T>.IsReadOnly
{
get