Last active
November 11, 2016 21:04
-
-
Save TorstenC/4dce0b81f97dd38b46ad187e3309408a to your computer and use it in GitHub Desktop.
Base Class for INotifyPropertyChanged Properties
This file contains hidden or 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 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