fork download
  1. using System;
  2. using System.ComponentModel;
  3. using System.Runtime.CompilerServices;
  4. using Windows.UI.Xaml.Data;
  5.  
  6. namespace AppNamespace.Common
  7. {
  8. /// <summary>
  9. /// Implementation of <see cref="INotifyPropertyChanged"/> to simplify models.
  10. /// </summary>
  11. [Windows.Foundation.Metadata.WebHostHidden]
  12. public abstract class BindableBase : INotifyPropertyChanged
  13. {
  14. /// <summary>
  15. /// Multicast event for property change notifications.
  16. /// </summary>
  17. public event PropertyChangedEventHandler PropertyChanged;
  18.  
  19. /// <summary>
  20. /// Checks if a property already matches a desired value. Sets the property and
  21. /// notifies listeners only when necessary.
  22. /// </summary>
  23. /// <typeparam name="T">Type of the property.</typeparam>
  24. /// <param name="storage">Reference to a property with both getter and setter.</param>
  25. /// <param name="value">Desired value for the property.</param>
  26. /// <param name="propertyName">Name of the property used to notify listeners. This
  27. /// value is optional and can be provided automatically when invoked from compilers that
  28. /// support CallerMemberName.</param>
  29. /// <returns>True if the value was changed, false if the existing value matched the
  30. /// desired value.</returns>
  31. protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] String propertyName = null)
  32. {
  33. if (object.Equals(storage, value)) return false;
  34.  
  35. storage = value;
  36. this.OnPropertyChanged(propertyName);
  37. return true;
  38. }
  39.  
  40. /// <summary>
  41. /// Notifies listeners that a property value has changed.
  42. /// </summary>
  43. /// <param name="propertyName">Name of the property used to notify listeners. This
  44. /// value is optional and can be provided automatically when invoked from compilers
  45. /// that support <see cref="CallerMemberNameAttribute"/>.</param>
  46. protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
  47. {
  48. var eventHandler = this.PropertyChanged;
  49. if (eventHandler != null)
  50. {
  51. eventHandler(this, new PropertyChangedEventArgs(propertyName));
  52. }
  53. }
  54. }
  55. }
  56.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty