fork download
  1. using System;
  2. using System.ComponentModel;
  3.  
  4. public interface IExample
  5. {
  6. string A { get; set; }
  7. }
  8.  
  9. public class Example: IExample, INotifyPropertyChanged
  10. {
  11. public Example()
  12. {
  13. }
  14.  
  15. /// Does not works properly...
  16. string fooString;
  17. string IExample.A
  18. {
  19. get { return this.fooString; }
  20. set
  21. {
  22. this.fooString= value;
  23. onPropertyChange("A");
  24. }
  25. }
  26.  
  27. PropertyChangedEventHandler propertyChangedHandler;
  28.  
  29. private void onPropertyChange(string propertyName)
  30. {
  31. if (this.propertyChangedHandler != null)
  32. propertyChangedHandler(this, new PropertyChangedEventArgs(propertyName));
  33. }
  34.  
  35. event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
  36. {
  37. add { this.propertyChangedHandler += value; }
  38. remove { this.propertyChangedHandler -= value; }
  39. }
  40.  
  41. }
  42.  
  43. public class Test
  44. {
  45. static void OnAChanged( object sender, PropertyChangedEventArgs e)
  46. {
  47. Console.WriteLine("A Changed.");
  48. }
  49.  
  50. public static void Main()
  51. {
  52. var example = new Example();
  53. ((INotifyPropertyChanged)example).PropertyChanged += OnAChanged;
  54. ((IExample)example).A = "new string";
  55. }
  56. }
Success #stdin #stdout 0.03s 33872KB
stdin
Standard input is empty
stdout
A Changed.