Guest User

Untitled

a guest
Jan 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. public class BaseViewModel : INotifyPropertyChanged
  2. {
  3. #region INotifyPropertyChanged Members
  4. /// <summary>
  5. /// Raised when a property on this object has a new value.
  6. /// </summary>
  7. public event PropertyChangedEventHandler PropertyChanged;
  8.  
  9. /// <summary>
  10. /// Raises this object's PropertyChanged event.
  11. /// </summary>
  12. /// <param name="propertyName">The property that has a new value.</param>
  13. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  14. {
  15. this.VerifyPropertyName(propertyName);
  16.  
  17. if (this.PropertyChanged != null)
  18. {
  19. //var e = new PropertyChangedEventArgs(propertyName);
  20. //this.PropertyChanged(this, e);
  21.  
  22. PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  23. }
  24. }
  25. #endregion
  26.  
  27. #region Debugging Aides
  28.  
  29. /// <summary>
  30. /// Warns the developer if this object does not have
  31. /// a public property with the specified name. This
  32. /// method does not exist in a Release build.
  33. /// </summary>
  34. [Conditional("DEBUG")]
  35. [DebuggerStepThrough]
  36. public virtual void VerifyPropertyName(string propertyName)
  37. {
  38. // Verify that the property name matches a real,
  39. // public, instance property on this object.
  40. if (TypeDescriptor.GetProperties(this)[propertyName] == null)
  41. {
  42. string msg = "Invalid property name: " + propertyName;
  43.  
  44. if (this.ThrowOnInvalidPropertyName)
  45. throw new Exception(msg);
  46. else
  47. Debug.Fail(msg);
  48. }
  49. }
  50.  
  51. /// <summary>
  52. /// Returns whether an exception is thrown, or if a Debug.Fail() is used
  53. /// when an invalid property name is passed to the VerifyPropertyName method.
  54. /// The default value is false, but subclasses used by unit tests might
  55. /// override this property's getter to return true.
  56. /// </summary>
  57. protected virtual bool ThrowOnInvalidPropertyName { get; private set; }
  58. #endregion
  59. }
Add Comment
Please, Sign In to add comment