NotifyPropertyChangedExtension.cs 660 B

123456789101112131415161718
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Runtime.CompilerServices;
  5. namespace ConfigureWindow.domain
  6. {
  7. public static class NotifyPropertyChangedExtension
  8. {
  9. public static bool MutateVerbose<TField>(this INotifyPropertyChanged _, ref TField field, TField newValue, Action<PropertyChangedEventArgs> raise, [CallerMemberName] string propertyName = null)
  10. {
  11. if (EqualityComparer<TField>.Default.Equals(field, newValue)) return false;
  12. field = newValue;
  13. raise?.Invoke(new PropertyChangedEventArgs(propertyName));
  14. return true;
  15. }
  16. }
  17. }