Skip to content

Instantly share code, notes, and snippets.

@moraismateus
Created May 13, 2022 05:21
Show Gist options
  • Save moraismateus/d4f955ea601d4214052358fbfe4763d3 to your computer and use it in GitHub Desktop.
Save moraismateus/d4f955ea601d4214052358fbfe4763d3 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace YourNamespace.Namespace
{
public class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment