Skip to content

Instantly share code, notes, and snippets.

@zafe
Created April 13, 2020 04:30
Show Gist options
  • Save zafe/6be0e4e7c7e25dd825ce020d11cd933f to your computer and use it in GitHub Desktop.
Save zafe/6be0e4e7c7e25dd825ce020d11cd933f to your computer and use it in GitHub Desktop.
public abstract class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected bool SetProperty<T>(ref T field, T newValue, [CallerMemberName]string propertyName = null)
{
if(!EqualityComparer<T>.Default.Equals(field, newValue))
{
field = newValue;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment