Last active
September 10, 2024 04:42
-
-
Save papinko/81488cf057182294b041d4645e9100ef to your computer and use it in GitHub Desktop.
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.Collections.Generic; | |
using System.ComponentModel; | |
using System.Runtime.CompilerServices; | |
public abstract class ObservableObject : INotifyPropertyChanged | |
{ | |
public event PropertyChangedEventHandler PropertyChanged; | |
protected void OnPropertyChanged([CallerMemberName] string name = null) | |
{ | |
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); | |
} | |
protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = "") | |
{ | |
if (EqualityComparer<T>.Default.Equals(storage, value)) | |
return false; | |
storage = value; | |
this.OnPropertyChanged(propertyName); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment