NotifyPropertyChangedExtension.cs 702 B

1234567891011121314151617181920
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace CmwtatDigital.Domain
  9. {
  10. public static class NotifyPropertyChangedExtension
  11. {
  12. public static void MutateVerbose<TField>(this INotifyPropertyChanged instance, ref TField field, TField newValue, Action<PropertyChangedEventArgs> raise, [CallerMemberName] string propertyName = null)
  13. {
  14. if (EqualityComparer<TField>.Default.Equals(field, newValue)) return;
  15. field = newValue;
  16. raise?.Invoke(new PropertyChangedEventArgs(propertyName));
  17. }
  18. }
  19. }