Created
June 21, 2019 08:33
-
-
Save CapitanLiteral/cd9b8a9c88da10f208f3411e695ed110 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public event PropertyChangedEventHandler PropertyChanged; | |
protected void SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null) | |
{ | |
if (EqualityComparer<T>.Default.Equals(field, value)) return; | |
field = value; | |
OnPropertyChanged(propertyName); | |
} | |
protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = null) => | |
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ChattyClass tmp = new ChattyClass(); | |
tmp.PropertyChanged += (sender, e) => | |
{ | |
Console.WriteLine(string.Format("Property {0} has been updated", e.PropertyName)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment