fork download
  1. using System.ComponentModel;
  2. using System.Runtime.CompilerServices;
  3.  
  4. public class Program {
  5. public static void Main() {
  6. var x = new Test();
  7. x.Foo = 10;
  8. }
  9. }
  10. public class Test: INotifyPropertyChanged {
  11. private int foo;
  12. public int Foo { get => foo; set => this.Set(ref foo, value, PropertyChanged); }
  13. public event PropertyChangedEventHandler PropertyChanged;
  14. protected void OnPropertyChanged(string name) {
  15. PropertyChangedEventHandler handler = PropertyChanged;
  16. if (handler != null) handler(this, new PropertyChangedEventArgs(name));
  17. }
  18. }
  19.  
  20. public static class Extensions {
  21. public static void Set<T>(
  22. this INotifyPropertyChanged source, ref T property, T value, PropertyChangedEventHandler handler, [CallerMemberName]string propertyName = "") {
  23. property = value;
  24. handler?.Invoke(source, new PropertyChangedEventArgs(propertyName));
  25. }
  26. }
  27.  
  28. //https://pt.stackoverflow.com/q/347780/101
Success #stdin #stdout 0.01s 15016KB
stdin
Standard input is empty
stdout
Standard output is empty