Skip to content

Instantly share code, notes, and snippets.

@CapitanLiteral
Created June 21, 2019 08:33
Show Gist options
  • Save CapitanLiteral/cd9b8a9c88da10f208f3411e695ed110 to your computer and use it in GitHub Desktop.
Save CapitanLiteral/cd9b8a9c88da10f208f3411e695ed110 to your computer and use it in GitHub Desktop.
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));
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