-
-
Save devjaime/cc1a98cf1703264347f91bcdb6514230 to your computer and use it in GitHub Desktop.
ObservableObject.cs
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
| using System; | |
| using System.Collections.Generic; | |
| using System.ComponentModel; | |
| using System.Runtime.CompilerServices; | |
| namespace Acelerometro.ViewModel | |
| { | |
| public class ObservableObject : INotifyPropertyChanged | |
| { | |
| protected virtual bool SetProperty<T>(ref T backingStore, T value, [CallerMemberName]string propertyName = "", Action onChanged = null, Func<T, T, bool> validateValue = null) | |
| { | |
| if (EqualityComparer<T>.Default.Equals(backingStore, value)) | |
| return false; | |
| if (validateValue != null && !validateValue(backingStore, value)) | |
| return false; | |
| backingStore = value; | |
| onChanged?.Invoke(); | |
| OnPropertyChanged(propertyName); | |
| return true; | |
| } | |
| public event PropertyChangedEventHandler PropertyChanged; | |
| protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = "") => | |
| PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment