using System.ComponentModel;
using System.Runtime.CompilerServices;
public static void Main() {
public class Test: INotifyPropertyChanged {
public int Foo { get => foo; set => this.Set(ref foo, value, PropertyChanged); }
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name) {
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(name));
public static class Extensions {
public static void Set<T>(
this INotifyPropertyChanged source, ref T property, T value, PropertyChangedEventHandler handler, [CallerMemberName]string propertyName = "") {
handler?.Invoke(source, new PropertyChangedEventArgs(propertyName));