Microsoft should have implemented something snappy for INotifyPropertyChanged
, like in the automatic properties, just specify {get; set; notify;}
I
I keep this around as a snippet. C# 6 adds some nice syntax for invoking the handler.
// INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private void Set(ref T property, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer.Default.Equals(property, value) == false)
{
property = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}