Skip to content

Instantly share code, notes, and snippets.

@TorstenC
Last active November 11, 2016 21:04
Show Gist options
  • Select an option

  • Save TorstenC/4dce0b81f97dd38b46ad187e3309408a to your computer and use it in GitHub Desktop.

Select an option

Save TorstenC/4dce0b81f97dd38b46ad187e3309408a to your computer and use it in GitHub Desktop.
Base Class for INotifyPropertyChanged Properties
public class NotifyBase : System.ComponentModel.INotifyPropertyChanged {
protected void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null) {
PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected bool SetField<T>(ref T field, T value, [System.Runtime.CompilerServices.CallerMemberName] string propertyName = null) {
if(EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
}
//usage example
//public FileStatus Status {
// get { return this._Status; }
// protected set { SetField(ref this._Status, value); }
//}
//public FileStatus _Status = FileStatus.unknown;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment