summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Hoefling <andrew@hoeflingsoftware.com>2019-03-04 20:16:16 -0500
committerSantiago Fernandez Madero <safern@microsoft.com>2019-03-08 11:20:58 -0800
commit0f5aee3560635d2c58c023578d00d7955a995163 (patch)
treec8ebfc0992ffbc9e16df6769288bab02117f705b /src
parentd74fa42f811dbe28a8c12ae39122f8d110fbfa5c (diff)
downloadcoreclr-0f5aee3560635d2c58c023578d00d7955a995163.tar.gz
coreclr-0f5aee3560635d2c58c023578d00d7955a995163.tar.bz2
coreclr-0f5aee3560635d2c58c023578d00d7955a995163.zip
Added new Range Manipulation APIs for Collection<T> which propogate up to ObservableCollection<T>. AddRange, InsertRange, RemoveRange and Replace Range
Diffstat (limited to 'src')
-rw-r--r--src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs53
1 files changed, 53 insertions, 0 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 c96a1576f3..f0814e9ded 100644
--- a/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs
+++ b/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs
@@ -69,6 +69,8 @@ namespace System.Collections.ObjectModel
InsertItem(index, item);
}
+ public void AddRange(IEnumerable<T> collection) => InsertItemsRange(items.Count > 0 ? items.Count : 0, collection);
+
public void Clear()
{
if (items.IsReadOnly)
@@ -114,6 +116,8 @@ namespace System.Collections.ObjectModel
InsertItem(index, item);
}
+ public void InsertRange(int index, IEnumerable<T> collection) => InsertItemsRange(index, collection);
+
public bool Remove(T item)
{
if (items.IsReadOnly)
@@ -127,6 +131,14 @@ namespace System.Collections.ObjectModel
return true;
}
+ 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 RemoveAt(int index)
{
if (items.IsReadOnly)
@@ -162,6 +174,47 @@ namespace System.Collections.ObjectModel
items[index] = item;
}
+ protected virtual void InsertItemsRange(int index, IEnumerable<T> collection)
+ {
+ if (collection == null)
+ {
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list);
+ }
+
+ if (items.IsReadOnly)
+ {
+ ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
+ }
+
+ if (index < 0 || index > items.Count)
+ {
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
+ }
+
+ int i = 0;
+ foreach (var item in collection)
+ {
+ Insert(index + i, item);
+ i++;
+ }
+ }
+
+ protected virtual void RemoveItemsRange(int index, int count)
+ {
+ if (items.IsReadOnly)
+ {
+ ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
+ }
+
+ if (index < 0 || index > items.Count)
+ {
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
+ }
+
+ for (int i = index; i < (index + count); i++)
+ RemoveAt(index);
+ }
+
bool ICollection<T>.IsReadOnly
{
get