Advertisement
PtiTom

PropertyChanged

Jul 30th, 2014
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. public event PropertyChangedEventHandler PropertyChanged;
  2.  
  3. protected virtual void OnPropertyChanged(string propertyName)
  4. {
  5.     this.VerifyProperty(propertyName);
  6.  
  7.     PropertyChangedEventHandler handler = this.PropertyChanged;
  8.     if (handler != null)
  9.     {
  10.         handler(this, new PropertyChangedEventArgs(propertyName));
  11.     }
  12. }
  13.  
  14. [Conditional("DEBUG"), DebuggerStepThrough]
  15. private void VerifyProperty(string propertyName)
  16. {
  17.     Type type = this.GetType();
  18.  
  19.     // Look for a public property with the specified name.
  20.     PropertyInfo propInfo = type.GetProperty(propertyName);
  21.  
  22.     // If the property could not be found,
  23.     // alert the developer of the problem.
  24.     Debug.Assert(propInfo != null, string.Format("{0} is not a public property of {1}", propertyName, type.FullName));
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement