CollectionChangedTracker.cs 742 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Collections.Specialized;
  3. namespace Avalonia.Base.UnitTests.Collections
  4. {
  5. internal class CollectionChangedTracker
  6. {
  7. public CollectionChangedTracker(INotifyCollectionChanged collection)
  8. {
  9. collection.CollectionChanged += CollectionChanged;
  10. }
  11. public NotifyCollectionChangedEventArgs Args { get; private set; }
  12. public void Reset()
  13. {
  14. Args = null;
  15. }
  16. private void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
  17. {
  18. if (Args != null)
  19. {
  20. throw new Exception("CollectionChanged called more than once.");
  21. }
  22. Args = e;
  23. }
  24. }
  25. }