Advertisement
Shimmy

Untitled

Jan 22nd, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1.  
  2. for (int i = index; i < max; i++)
  3. {
  4. //parallel position
  5. if (i < rangeEnd && i < addedCount - index)
  6. {
  7. T old = this[i],
  8. @new = list[i - index];
  9.  
  10. if (comparer.Equals(old, @new))
  11. {
  12. OnRangeReplaced(i, newCluster, oldCluster);
  13. continue;
  14. }
  15. else
  16. {
  17. Items[i] = @new;
  18. newCluster.Add(@new);
  19. oldCluster.Add(old);
  20.  
  21. changesMade = true;
  22. }
  23. }
  24. else
  25. {
  26. OnRangeReplaced(i, newCluster, oldCluster);
  27.  
  28. //exceeding position
  29. var items = (List<T>)Items;
  30. if (rangeEnd > addedCount - index)
  31. {
  32. var removedCount = rangeEnd - addedCount;
  33. T[] removed = new T[removedCount];
  34. items.CopyTo(i, removed, 0, removed.Length);
  35. items.RemoveRange(i, removedCount);
  36. OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removed, i));
  37. }
  38. //new position
  39. else
  40. {
  41. var k = i - index;
  42. T[] added = new T[addedCount - k];
  43. for (int j = k; j < addedCount; j++)
  44. {
  45. T @new = list[j];
  46. added[j - k] = @new;
  47. }
  48. items.InsertRange(i, added);
  49. OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, added, i));
  50. }
  51. break;
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement