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
Added new OnCollectionChanged overloads to reduce need for additional…
Browse files Browse the repository at this point in the history
… if checks.
  • Loading branch information
Andrew Hoefling committed Mar 11, 2019
1 parent 91cf013 commit bf4b07b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ protected override void ReplaceItemsRange(int index, int count, IEnumerable<T> c

OnCountPropertyChanged();
OnIndexerPropertyChanged();
OnCollectionChanged(NotifyCollectionChangedAction.Replace, itemsToReplace, collection, index);
OnCollectionChanged(NotifyCollectionChangedAction.Replace, itemsToReplace, (IList)collection, index);
}


Expand Down Expand Up @@ -397,14 +397,15 @@ protected void CheckReentrancy()
/// </summary>
private void OnCollectionChanged(NotifyCollectionChangedAction action, object item, int index)
{
if (item is IList)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, (IList)item, index));
}
else
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, item, index));
}
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>
Expand All @@ -420,14 +421,15 @@ private void OnCollectionChanged(NotifyCollectionChangedAction action, object it
/// </summary>
private void OnCollectionChanged(NotifyCollectionChangedAction action, object oldItem, object newItem, int index)
{
if (oldItem is IList && newItem is IList)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, (IList)oldItem, (IList)newItem, index));
}
else
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, newItem, oldItem, index));
}
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ public static void RemoveRange_NotifyCollectionChanged_EventArgs_IndexOfZero_Tes
}

[Fact]
public static void RemoveRange_NotifyCollectionChanged_EventArgs_IndexMiddle_Test()
public static void RemoveRange_NotifyCollectionChanged_EventArgs_IndexMiddle_Test()
{
int[] initialData = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
int[] actualDataRemoved = new int[0];
Expand Down

0 comments on commit bf4b07b

Please sign in to comment.