CollectionChangedTracker.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // -----------------------------------------------------------------------
  2. // <copyright file="CollectionChangedTracker.cs" company="Steven Kirk">
  3. // Copyright 2015 MIT Licence. See licence.md for more information.
  4. // </copyright>
  5. // -----------------------------------------------------------------------
  6. namespace Perspex.Base.UnitTests.Collections
  7. {
  8. using System;
  9. using System.Collections.Specialized;
  10. internal class CollectionChangedTracker
  11. {
  12. public CollectionChangedTracker(INotifyCollectionChanged collection)
  13. {
  14. collection.CollectionChanged += this.CollectionChanged;
  15. }
  16. public NotifyCollectionChangedEventArgs Args { get; private set; }
  17. public void Reset()
  18. {
  19. this.Args = null;
  20. }
  21. private void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
  22. {
  23. if (this.Args != null)
  24. {
  25. throw new Exception("CollectionChanged called more than once.");
  26. }
  27. this.Args = e;
  28. }
  29. }
  30. }