Skip to content

Commit

Permalink
Revert "Added Range Manipulation APIs to Collection<T> and Observabl…
Browse files Browse the repository at this point in the history
…eCollection<T> (dotnet/corefx#35772)" (dotnet/corefx#38115)

* Revert "Added Range Manipulation APIs to Collection<T> and ObservableCollection<T> (dotnet/corefx#35772)"

This reverts commit dotnet/corefx@b705522.

* Baseline API Compat errors

* Fix baseline vs netstandard


Commit migrated from dotnet/corefx@d250626
  • Loading branch information
safern authored and wtgodbe committed May 31, 2019
1 parent 3493114 commit 18c2fa1
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 1,057 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public class ObservableCollection<T> : Collection<T>, INotifyCollectionChanged,
[NonSerialized]
private int _blockReentrancyCount;

[NonSerialized]
private bool _skipRaisingEvents;

/// <summary>
/// Initializes a new instance of ObservableCollection that is empty and has default initial capacity.
/// </summary>
Expand Down Expand Up @@ -124,95 +121,9 @@ protected override void RemoveItem(int index)

base.RemoveItem(index);

if (!_skipRaisingEvents)
{
OnCountPropertyChanged();
OnIndexerPropertyChanged();
OnCollectionChanged(NotifyCollectionChangedAction.Remove, removedItem, index);
}
}

/// <summary>
/// Called by base class Collection&lt;T&gt; when a count of items is removed from the list;
/// raises a CollectionChanged event to any listeners.
/// </summary>
protected override void RemoveItemsRange(int index, int count)
{
CheckReentrancy();

T[] removedItems = null;

bool ignore = _skipRaisingEvents;
if (!ignore)
{
_skipRaisingEvents = true;

if (count > 0)
{
removedItems = new T[count];
for (int i = 0; i < count; i++)
{
removedItems[i] = this[index + i];
}
}
}

try
{
base.RemoveItemsRange(index, count);
}
finally
{
if (!ignore)
{
_skipRaisingEvents = false;
}
}

if (count > 0 && !_skipRaisingEvents)
{
OnCountPropertyChanged();
OnIndexerPropertyChanged();
OnCollectionChanged(NotifyCollectionChangedAction.Remove, removedItems, index);
}
}

/// <summary>
/// Called by base class Collection&lt;T&gt; when a collection of items is added to list;
/// raises a CollectionChanged event to any listeners.
/// </summary>
protected override void ReplaceItemsRange(int index, int count, IEnumerable<T> collection)
{
CheckReentrancy();

_skipRaisingEvents = true;

T[] itemsToReplace = new T[count - index];
for (int i = index; i < count; i++)
{
itemsToReplace[i] = this[i];
}

try
{
base.ReplaceItemsRange(index, count, collection);
}
finally
{
_skipRaisingEvents = false;
}

if (!_skipRaisingEvents)
{
IList newItems = collection is IList list ? list : new List<T>(collection);

if (newItems.Count > 0)
{
OnCountPropertyChanged();
OnIndexerPropertyChanged();
OnCollectionChanged(NotifyCollectionChangedAction.Replace, itemsToReplace, newItems, index);
}
}
OnCountPropertyChanged();
OnIndexerPropertyChanged();
OnCollectionChanged(NotifyCollectionChangedAction.Remove, removedItem, index);
}

/// <summary>
Expand All @@ -224,51 +135,9 @@ protected override void InsertItem(int index, T item)
CheckReentrancy();
base.InsertItem(index, item);

if (!_skipRaisingEvents)
{
OnCountPropertyChanged();
OnIndexerPropertyChanged();
OnCollectionChanged(NotifyCollectionChangedAction.Add, item, index);
}
}

/// <summary>
/// Called by base class Collection&lt;T&gt; when a collection of items is added to list;
/// raises a CollectionChanged event to any listeners.
/// </summary>
protected override void InsertItemsRange(int index, IEnumerable<T> collection)
{
CheckReentrancy();

bool ignore = _skipRaisingEvents;
if (!ignore)
{
_skipRaisingEvents = true;
}

try
{
base.InsertItemsRange(index, collection);
}
finally
{
if (!ignore)
{
_skipRaisingEvents = false;
}
}

if (!_skipRaisingEvents)
{
IList newItems = collection is IList list ? list : new List<T>(collection);

if (newItems.Count > 0)
{
OnCountPropertyChanged();
OnIndexerPropertyChanged();
OnCollectionChanged(NotifyCollectionChangedAction.Add, newItems, index);
}
}
OnCountPropertyChanged();
OnIndexerPropertyChanged();
OnCollectionChanged(NotifyCollectionChangedAction.Add, item, index);
}

/// <summary>
Expand Down Expand Up @@ -396,14 +265,6 @@ private void OnCollectionChanged(NotifyCollectionChangedAction action, object it
OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, item, index));
}

/// <summary>
/// Helper to raise CollectionChanged event to any listeners
/// </summary>
private void OnCollectionChanged(NotifyCollectionChangedAction action, IList items, int index)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, items, index));
}

/// <summary>
/// Helper to raise CollectionChanged event to any listeners
/// </summary>
Expand All @@ -420,14 +281,6 @@ private void OnCollectionChanged(NotifyCollectionChangedAction action, object ol
OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, newItem, oldItem, index));
}

/// <summary>
/// Helper to raise CollectionChanged event to any listeners
/// </summary>
private void OnCollectionChanged(NotifyCollectionChangedAction action, IList oldItems, IList newItems, int index)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, newItems, oldItems, index));
}

/// <summary>
/// Helper to raise CollectionChanged event with action == Reset to any listeners
/// </summary>
Expand Down
Loading

0 comments on commit 18c2fa1

Please sign in to comment.