NotifyingBase.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) The Perspex Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System.ComponentModel;
  4. using System.Linq;
  5. namespace Perspex.Markup.UnitTests.Data
  6. {
  7. public class NotifyingBase : INotifyPropertyChanged
  8. {
  9. private PropertyChangedEventHandler _propertyChanged;
  10. public event PropertyChangedEventHandler PropertyChanged
  11. {
  12. add
  13. {
  14. _propertyChanged += value;
  15. ++SubscriptionCount;
  16. }
  17. remove
  18. {
  19. if (_propertyChanged?.GetInvocationList().Contains(value) == true)
  20. {
  21. _propertyChanged -= value;
  22. --SubscriptionCount;
  23. }
  24. }
  25. }
  26. public int SubscriptionCount
  27. {
  28. get;
  29. private set;
  30. }
  31. protected void RaisePropertyChanged(string propertyName)
  32. {
  33. _propertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  34. }
  35. }
  36. }