Skip to content

Instantly share code, notes, and snippets.

@papinko
Last active September 10, 2024 04:42
Show Gist options
  • Save papinko/81488cf057182294b041d4645e9100ef to your computer and use it in GitHub Desktop.
Save papinko/81488cf057182294b041d4645e9100ef to your computer and use it in GitHub Desktop.
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