NotifyingBase.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) The Avalonia 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. using System.Runtime.CompilerServices;
  6. namespace Avalonia.UnitTests
  7. {
  8. public class NotifyingBase : INotifyPropertyChanged
  9. {
  10. private PropertyChangedEventHandler _propertyChanged;
  11. public event PropertyChangedEventHandler PropertyChanged
  12. {
  13. add
  14. {
  15. _propertyChanged += value;
  16. ++PropertyChangedSubscriptionCount;
  17. }
  18. remove
  19. {
  20. if (_propertyChanged?.GetInvocationList().Contains(value) == true)
  21. {
  22. _propertyChanged -= value;
  23. --PropertyChangedSubscriptionCount;
  24. }
  25. }
  26. }
  27. public int PropertyChangedSubscriptionCount
  28. {
  29. get;
  30. private set;
  31. }
  32. public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
  33. {
  34. _propertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  35. }
  36. }
  37. }