ObservableRangeCollection.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. // using System;
  2. // using System.Collections;
  3. // using System.Collections.ObjectModel;
  4. //
  5. // namespace InABox.Mobile
  6. // {
  7. // // Licensed to the .NET Foundation under one or more agreements.
  8. // // The .NET Foundation licenses this file to you under the MIT license.
  9. // // See the LICENSE file in the project root for more information.
  10. //
  11. // using System.Collections.Generic;
  12. // using System.Collections.Specialized;
  13. // using System.ComponentModel;
  14. // using System.Diagnostics;
  15. // using System.Linq;
  16. //
  17. // /// <summary>
  18. // /// Implementation of a dynamic data collection based on generic Collection&lt;T&gt;,
  19. // /// implementing INotifyCollectionChanged to notify listeners
  20. // /// when items get added, removed or the whole list is refreshed.
  21. // /// </summary>
  22. // public class CoreObservableCollection<T> : ObservableCollection<T>
  23. // {
  24. // //------------------------------------------------------
  25. // //
  26. // // Private Fields
  27. // //
  28. // //------------------------------------------------------
  29. //
  30. // #region Private Fields
  31. // [NonSerialized]
  32. // private DeferredEventsCollection? _deferredEvents;
  33. // #endregion Private Fields
  34. //
  35. //
  36. // //------------------------------------------------------
  37. // //
  38. // // Constructors
  39. // //
  40. // //------------------------------------------------------
  41. //
  42. // #region Constructors
  43. // /// <summary>
  44. // /// Initializes a new instance of ObservableCollection that is empty and has default initial capacity.
  45. // /// </summary>
  46. // public CoreObservableCollection() { }
  47. //
  48. // /// <summary>
  49. // /// Initializes a new instance of the ObservableCollection class that contains
  50. // /// elements copied from the specified collection and has sufficient capacity
  51. // /// to accommodate the number of elements copied.
  52. // /// </summary>
  53. // /// <param name="collection">The collection whose elements are copied to the new list.</param>
  54. // /// <remarks>
  55. // /// The elements are copied onto the ObservableCollection in the
  56. // /// same order they are read by the enumerator of the collection.
  57. // /// </remarks>
  58. // /// <exception cref="ArgumentNullException"> collection is a null reference </exception>
  59. // public CoreObservableCollection(IEnumerable<T> collection) : base(collection) { }
  60. //
  61. // /// <summary>
  62. // /// Initializes a new instance of the ObservableCollection class
  63. // /// that contains elements copied from the specified list
  64. // /// </summary>
  65. // /// <param name="list">The list whose elements are copied to the new list.</param>
  66. // /// <remarks>
  67. // /// The elements are copied onto the ObservableCollection in the
  68. // /// same order they are read by the enumerator of the list.
  69. // /// </remarks>
  70. // /// <exception cref="ArgumentNullException"> list is a null reference </exception>
  71. // public CoreObservableCollection(List<T> list) : base(list) { }
  72. //
  73. // #endregion Constructors
  74. //
  75. // //------------------------------------------------------
  76. // //
  77. // // Public Properties
  78. // //
  79. // //------------------------------------------------------
  80. //
  81. // #region Public Properties
  82. // EqualityComparer<T>? _Comparer;
  83. // public EqualityComparer<T> Comparer
  84. // {
  85. // get => _Comparer ??= EqualityComparer<T>.Default;
  86. // private set => _Comparer = value;
  87. // }
  88. //
  89. // /// <summary>
  90. // /// Gets or sets a value indicating whether this collection acts as a <see cref="HashSet{T}"/>,
  91. // /// disallowing duplicate items, based on <see cref="Comparer"/>.
  92. // /// This might indeed consume background performance, but in the other hand,
  93. // /// it will pay off in UI performance as less required UI updates are required.
  94. // /// </summary>
  95. // public bool AllowDuplicates { get; set; } = true;
  96. //
  97. // #endregion Public Properties
  98. //
  99. // //------------------------------------------------------
  100. // //
  101. // // Public Methods
  102. // //
  103. // //------------------------------------------------------
  104. //
  105. // #region Public Methods
  106. //
  107. // /// <summary>
  108. // /// Adds the elements of the specified collection to the end of the <see cref="ObservableCollection{T}"/>.
  109. // /// </summary>
  110. // /// <param name="collection">
  111. // /// The collection whose elements should be added to the end of the <see cref="ObservableCollection{T}"/>.
  112. // /// The collection itself cannot be null, but it can contain elements that are null, if type T is a reference type.
  113. // /// </param>
  114. // /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception>
  115. // public void AddRange(IEnumerable<T> collection)
  116. // {
  117. // InsertRange(Count, collection);
  118. // }
  119. //
  120. // /// <summary>
  121. // /// Inserts the elements of a collection into the <see cref="ObservableCollection{T}"/> at the specified index.
  122. // /// </summary>
  123. // /// <param name="index">The zero-based index at which the new elements should be inserted.</param>
  124. // /// <param name="collection">The collection whose elements should be inserted into the List<T>.
  125. // /// The collection itself cannot be null, but it can contain elements that are null, if type T is a reference type.</param>
  126. // /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception>
  127. // /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is not in the collection range.</exception>
  128. // public void InsertRange(int index, IEnumerable<T> collection)
  129. // {
  130. // if (collection == null)
  131. // throw new ArgumentNullException(nameof(collection));
  132. // if (index < 0)
  133. // throw new ArgumentOutOfRangeException(nameof(index));
  134. // if (index > Count)
  135. // throw new ArgumentOutOfRangeException(nameof(index));
  136. //
  137. // if (!AllowDuplicates)
  138. // collection =
  139. // collection
  140. // .Distinct(Comparer)
  141. // .Where(item => !Items.Contains(item, Comparer))
  142. // .ToList();
  143. //
  144. // if (collection is ICollection<T> countable)
  145. // {
  146. // if (countable.Count == 0)
  147. // return;
  148. // }
  149. // else if (!collection.Any())
  150. // return;
  151. //
  152. // CheckReentrancy();
  153. //
  154. // //expand the following couple of lines when adding more constructors.
  155. // var target = (List<T>)Items;
  156. // target.InsertRange(index, collection);
  157. //
  158. // OnEssentialPropertiesChanged();
  159. //
  160. // if (!(collection is IList list))
  161. // list = new List<T>(collection);
  162. //
  163. // OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, list, index));
  164. // }
  165. //
  166. //
  167. // /// <summary>
  168. // /// Removes the first occurence of each item in the specified collection from the <see cref="ObservableCollection{T}"/>.
  169. // /// </summary>
  170. // /// <param name="collection">The items to remove.</param>
  171. // /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception>
  172. // public void RemoveRange(IEnumerable<T> collection)
  173. // {
  174. // if (collection == null)
  175. // throw new ArgumentNullException(nameof(collection));
  176. //
  177. // if (Count == 0)
  178. // return;
  179. // else if (collection is ICollection<T> countable)
  180. // {
  181. // if (countable.Count == 0)
  182. // return;
  183. // else if (countable.Count == 1)
  184. // using (IEnumerator<T> enumerator = countable.GetEnumerator())
  185. // {
  186. // enumerator.MoveNext();
  187. // Remove(enumerator.Current);
  188. // return;
  189. // }
  190. // }
  191. // else if (!collection.Any())
  192. // return;
  193. //
  194. // CheckReentrancy();
  195. //
  196. // var clusters = new Dictionary<int, List<T>>();
  197. // var lastIndex = -1;
  198. // List<T>? lastCluster = null;
  199. // foreach (T item in collection)
  200. // {
  201. // var index = IndexOf(item);
  202. // if (index < 0)
  203. // continue;
  204. //
  205. // Items.RemoveAt(index);
  206. //
  207. // if (lastIndex == index && lastCluster != null)
  208. // lastCluster.Add(item);
  209. // else
  210. // clusters[lastIndex = index] = lastCluster = new List<T> { item };
  211. // }
  212. //
  213. // OnEssentialPropertiesChanged();
  214. //
  215. // if (Count == 0)
  216. // OnCollectionReset();
  217. // else
  218. // foreach (KeyValuePair<int, List<T>> cluster in clusters)
  219. // OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, cluster.Value, cluster.Key));
  220. //
  221. // }
  222. //
  223. // /// <summary>
  224. // /// Iterates over the collection and removes all items that satisfy the specified match.
  225. // /// </summary>
  226. // /// <remarks>The complexity is O(n).</remarks>
  227. // /// <param name="match"></param>
  228. // /// <returns>Returns the number of elements that where </returns>
  229. // /// <exception cref="ArgumentNullException"><paramref name="match"/> is null.</exception>
  230. // public int RemoveAll(Predicate<T> match)
  231. // {
  232. // return RemoveAll(0, Count, match);
  233. // }
  234. //
  235. // /// <summary>
  236. // /// Iterates over the specified range within the collection and removes all items that satisfy the specified match.
  237. // /// </summary>
  238. // /// <remarks>The complexity is O(n).</remarks>
  239. // /// <param name="index">The index of where to start performing the search.</param>
  240. // /// <param name="count">The number of items to iterate on.</param>
  241. // /// <param name="match"></param>
  242. // /// <returns>Returns the number of elements that where </returns>
  243. // /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is out of range.</exception>
  244. // /// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is out of range.</exception>
  245. // /// <exception cref="ArgumentNullException"><paramref name="match"/> is null.</exception>
  246. // public int RemoveAll(int index, int count, Predicate<T> match)
  247. // {
  248. // if (index < 0)
  249. // throw new ArgumentOutOfRangeException(nameof(index));
  250. // if (count < 0)
  251. // throw new ArgumentOutOfRangeException(nameof(count));
  252. // if (index + count > Count)
  253. // throw new ArgumentOutOfRangeException(nameof(index));
  254. // if (match == null)
  255. // throw new ArgumentNullException(nameof(match));
  256. //
  257. // if (Count == 0)
  258. // return 0;
  259. //
  260. // List<T>? cluster = null;
  261. // var clusterIndex = -1;
  262. // var removedCount = 0;
  263. //
  264. // using (BlockReentrancy())
  265. // using (DeferEvents())
  266. // {
  267. // for (var i = 0; i < count; i++, index++)
  268. // {
  269. // T item = Items[index];
  270. // if (match(item))
  271. // {
  272. // Items.RemoveAt(index);
  273. // removedCount++;
  274. //
  275. // if (clusterIndex == index)
  276. // {
  277. // Debug.Assert(cluster != null);
  278. // cluster!.Add(item);
  279. // }
  280. // else
  281. // {
  282. // cluster = new List<T> { item };
  283. // clusterIndex = index;
  284. // }
  285. //
  286. // index--;
  287. // }
  288. // else if (clusterIndex > -1)
  289. // {
  290. // OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, cluster, clusterIndex));
  291. // clusterIndex = -1;
  292. // cluster = null;
  293. // }
  294. // }
  295. //
  296. // if (clusterIndex > -1)
  297. // OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, cluster, clusterIndex));
  298. // }
  299. //
  300. // if (removedCount > 0)
  301. // OnEssentialPropertiesChanged();
  302. //
  303. // return removedCount;
  304. // }
  305. //
  306. // /// <summary>
  307. // /// Removes a range of elements from the <see cref="ObservableCollection{T}"/>>.
  308. // /// </summary>
  309. // /// <param name="index">The zero-based starting index of the range of elements to remove.</param>
  310. // /// <param name="count">The number of elements to remove.</param>
  311. // /// <exception cref="ArgumentOutOfRangeException">The specified range is exceeding the collection.</exception>
  312. // public void RemoveRange(int index, int count)
  313. // {
  314. // if (index < 0)
  315. // throw new ArgumentOutOfRangeException(nameof(index));
  316. // if (count < 0)
  317. // throw new ArgumentOutOfRangeException(nameof(count));
  318. // if (index + count > Count)
  319. // throw new ArgumentOutOfRangeException(nameof(index));
  320. //
  321. // if (count == 0)
  322. // return;
  323. //
  324. // if (count == 1)
  325. // {
  326. // RemoveItem(index);
  327. // return;
  328. // }
  329. //
  330. // //Items will always be List<T>, see constructors
  331. // var items = (List<T>)Items;
  332. // List<T> removedItems = items.GetRange(index, count);
  333. //
  334. // CheckReentrancy();
  335. //
  336. // items.RemoveRange(index, count);
  337. //
  338. // OnEssentialPropertiesChanged();
  339. //
  340. // if (Count == 0)
  341. // OnCollectionReset();
  342. // else
  343. // OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removedItems, index));
  344. // }
  345. //
  346. // /// <summary>
  347. // /// Clears the current collection and replaces it with the specified collection,
  348. // /// using <see cref="Comparer"/>.
  349. // /// </summary>
  350. // /// <param name="collection">The items to fill the collection with, after clearing it.</param>
  351. // /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception>
  352. // public void ReplaceRange(IEnumerable<T> collection)
  353. // {
  354. // ReplaceRange(0, Count, collection);
  355. // }
  356. //
  357. // /// <summary>
  358. // /// Removes the specified range and inserts the specified collection in its position, leaving equal items in equal positions intact.
  359. // /// </summary>
  360. // /// <param name="index">The index of where to start the replacement.</param>
  361. // /// <param name="count">The number of items to be replaced.</param>
  362. // /// <param name="collection">The collection to insert in that location.</param>
  363. // /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is out of range.</exception>
  364. // /// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is out of range.</exception>
  365. // /// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception>
  366. // /// <exception cref="ArgumentNullException"><paramref name="comparer"/> is null.</exception>
  367. // public void ReplaceRange(int index, int count, IEnumerable<T> collection)
  368. // {
  369. // if (index < 0)
  370. // throw new ArgumentOutOfRangeException(nameof(index));
  371. // if (count < 0)
  372. // throw new ArgumentOutOfRangeException(nameof(count));
  373. // if (index + count > Count)
  374. // throw new ArgumentOutOfRangeException(nameof(index));
  375. //
  376. // if (collection == null)
  377. // throw new ArgumentNullException(nameof(collection));
  378. //
  379. // if (!AllowDuplicates)
  380. // collection =
  381. // collection
  382. // .Distinct(Comparer)
  383. // .ToList();
  384. //
  385. // if (collection is ICollection<T> countable)
  386. // {
  387. // if (countable.Count == 0)
  388. // {
  389. // RemoveRange(index, count);
  390. // return;
  391. // }
  392. // }
  393. // else if (!collection.Any())
  394. // {
  395. // RemoveRange(index, count);
  396. // return;
  397. // }
  398. //
  399. // if (index + count == 0)
  400. // {
  401. // InsertRange(0, collection);
  402. // return;
  403. // }
  404. //
  405. // if (!(collection is IList<T> list))
  406. // list = new List<T>(collection);
  407. //
  408. // using (BlockReentrancy())
  409. // using (DeferEvents())
  410. // {
  411. // var rangeCount = index + count;
  412. // var addedCount = list.Count;
  413. //
  414. // var changesMade = false;
  415. // List<T>?
  416. // newCluster = null,
  417. // oldCluster = null;
  418. //
  419. //
  420. // int i = index;
  421. // for (; i < rangeCount && i - index < addedCount; i++)
  422. // {
  423. // //parallel position
  424. // T old = this[i], @new = list[i - index];
  425. // if (Comparer.Equals(old, @new))
  426. // {
  427. // OnRangeReplaced(i, newCluster!, oldCluster!);
  428. // continue;
  429. // }
  430. // else
  431. // {
  432. // Items[i] = @new;
  433. //
  434. // if (newCluster == null)
  435. // {
  436. // Debug.Assert(oldCluster == null);
  437. // newCluster = new List<T> { @new };
  438. // oldCluster = new List<T> { old };
  439. // }
  440. // else
  441. // {
  442. // newCluster.Add(@new);
  443. // oldCluster!.Add(old);
  444. // }
  445. //
  446. // changesMade = true;
  447. // }
  448. // }
  449. //
  450. // OnRangeReplaced(i, newCluster!, oldCluster!);
  451. //
  452. // //exceeding position
  453. // if (count != addedCount)
  454. // {
  455. // var items = (List<T>)Items;
  456. // if (count > addedCount)
  457. // {
  458. // var removedCount = rangeCount - addedCount;
  459. // T[] removed = new T[removedCount];
  460. // items.CopyTo(i, removed, 0, removed.Length);
  461. // items.RemoveRange(i, removedCount);
  462. // OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removed, i));
  463. // }
  464. // else
  465. // {
  466. // var k = i - index;
  467. // T[] added = new T[addedCount - k];
  468. // for (int j = k; j < addedCount; j++)
  469. // {
  470. // T @new = list[j];
  471. // added[j - k] = @new;
  472. // }
  473. // items.InsertRange(i, added);
  474. // OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, added, i));
  475. // }
  476. //
  477. // OnEssentialPropertiesChanged();
  478. // }
  479. // else if (changesMade)
  480. // {
  481. // OnIndexerPropertyChanged();
  482. // }
  483. // }
  484. // }
  485. //
  486. // #endregion Public Methods
  487. //
  488. //
  489. // //------------------------------------------------------
  490. // //
  491. // // Protected Methods
  492. // //
  493. // //------------------------------------------------------
  494. //
  495. // #region Protected Methods
  496. //
  497. // /// <summary>
  498. // /// Called by base class Collection&lt;T&gt; when the list is being cleared;
  499. // /// raises a CollectionChanged event to any listeners.
  500. // /// </summary>
  501. // protected override void ClearItems()
  502. // {
  503. // if (Count == 0)
  504. // return;
  505. //
  506. // CheckReentrancy();
  507. // base.ClearItems();
  508. // OnEssentialPropertiesChanged();
  509. // OnCollectionReset();
  510. // }
  511. //
  512. // /// <inheritdoc/>
  513. // protected override void InsertItem(int index, T item)
  514. // {
  515. // if (!AllowDuplicates && Items.Contains(item))
  516. // return;
  517. //
  518. // base.InsertItem(index, item);
  519. // }
  520. //
  521. // /// <inheritdoc/>
  522. // protected override void SetItem(int index, T item)
  523. // {
  524. // if (AllowDuplicates)
  525. // {
  526. // if (Comparer.Equals(this[index], item))
  527. // return;
  528. // }
  529. // else
  530. // if (Items.Contains(item, Comparer))
  531. // return;
  532. //
  533. // CheckReentrancy();
  534. // T oldItem = this[index];
  535. // base.SetItem(index, item);
  536. //
  537. // OnIndexerPropertyChanged();
  538. // OnCollectionChanged(NotifyCollectionChangedAction.Replace, oldItem!, item!, index);
  539. // }
  540. //
  541. // /// <summary>
  542. // /// Raise CollectionChanged event to any listeners.
  543. // /// Properties/methods modifying this ObservableCollection will raise
  544. // /// a collection changed event through this virtual method.
  545. // /// </summary>
  546. // /// <remarks>
  547. // /// When overriding this method, either call its base implementation
  548. // /// or call <see cref="BlockReentrancy"/> to guard against reentrant collection changes.
  549. // /// </remarks>
  550. // protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
  551. // {
  552. // if (_deferredEvents != null)
  553. // {
  554. // _deferredEvents.Add(e);
  555. // return;
  556. // }
  557. // base.OnCollectionChanged(e);
  558. // }
  559. //
  560. // protected virtual IDisposable DeferEvents() => new DeferredEventsCollection(this);
  561. //
  562. // #endregion Protected Methods
  563. //
  564. //
  565. // //------------------------------------------------------
  566. // //
  567. // // Private Methods
  568. // //
  569. // //------------------------------------------------------
  570. //
  571. // #region Private Methods
  572. //
  573. // /// <summary>
  574. // /// Helper to raise Count property and the Indexer property.
  575. // /// </summary>
  576. // void OnEssentialPropertiesChanged()
  577. // {
  578. // OnPropertyChanged(EventArgsCache.CountPropertyChanged);
  579. // OnIndexerPropertyChanged();
  580. // }
  581. //
  582. // /// <summary>
  583. // /// /// Helper to raise a PropertyChanged event for the Indexer property
  584. // /// /// </summary>
  585. // void OnIndexerPropertyChanged() =>
  586. // OnPropertyChanged(EventArgsCache.IndexerPropertyChanged);
  587. //
  588. // /// <summary>
  589. // /// Helper to raise CollectionChanged event to any listeners
  590. // /// </summary>
  591. // void OnCollectionChanged(NotifyCollectionChangedAction action, object oldItem, object newItem, int index) =>
  592. // OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, newItem, oldItem, index));
  593. //
  594. // /// <summary>
  595. // /// Helper to raise CollectionChanged event with action == Reset to any listeners
  596. // /// </summary>
  597. // void OnCollectionReset() =>
  598. // OnCollectionChanged(EventArgsCache.ResetCollectionChanged);
  599. //
  600. // /// <summary>
  601. // /// Helper to raise event for clustered action and clear cluster.
  602. // /// </summary>
  603. // /// <param name="followingItemIndex">The index of the item following the replacement block.</param>
  604. // /// <param name="newCluster"></param>
  605. // /// <param name="oldCluster"></param>
  606. // //TODO should have really been a local method inside ReplaceRange(int index, int count, IEnumerable<T> collection, IEqualityComparer<T> comparer),
  607. // //move when supported language version updated.
  608. // void OnRangeReplaced(int followingItemIndex, ICollection<T> newCluster, ICollection<T> oldCluster)
  609. // {
  610. // if (oldCluster == null || oldCluster.Count == 0)
  611. // {
  612. // Debug.Assert(newCluster == null || newCluster.Count == 0);
  613. // return;
  614. // }
  615. //
  616. // OnCollectionChanged(
  617. // new NotifyCollectionChangedEventArgs(
  618. // NotifyCollectionChangedAction.Replace,
  619. // new List<T>(newCluster),
  620. // new List<T>(oldCluster),
  621. // followingItemIndex - oldCluster.Count));
  622. //
  623. // oldCluster.Clear();
  624. // newCluster.Clear();
  625. // }
  626. //
  627. // #endregion Private Methods
  628. //
  629. // //------------------------------------------------------
  630. // //
  631. // // Private Types
  632. // //
  633. // //------------------------------------------------------
  634. //
  635. // #region Private Types
  636. // sealed class DeferredEventsCollection : List<NotifyCollectionChangedEventArgs>, IDisposable
  637. // {
  638. // readonly CoreObservableCollection<T> _collection;
  639. // public DeferredEventsCollection(CoreObservableCollection<T> collection)
  640. // {
  641. // Debug.Assert(collection != null);
  642. // Debug.Assert(collection._deferredEvents == null);
  643. // _collection = collection;
  644. // _collection._deferredEvents = this;
  645. // }
  646. //
  647. // public void Dispose()
  648. // {
  649. // _collection._deferredEvents = null;
  650. // foreach (var args in this)
  651. // _collection.OnCollectionChanged(args);
  652. // }
  653. // }
  654. //
  655. // #endregion Private Types
  656. //
  657. // }
  658. //
  659. // /// <remarks>
  660. // /// To be kept outside <see cref="ObservableCollection{T}"/>, since otherwise, a new instance will be created for each generic type used.
  661. // /// </remarks>
  662. // internal static class EventArgsCache
  663. // {
  664. // internal static readonly PropertyChangedEventArgs CountPropertyChanged = new PropertyChangedEventArgs("Count");
  665. // internal static readonly PropertyChangedEventArgs IndexerPropertyChanged = new PropertyChangedEventArgs("Item[]");
  666. // internal static readonly NotifyCollectionChangedEventArgs ResetCollectionChanged = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
  667. // }
  668. // }