code_junkie

C# Preprocessor

Nov 10th, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. public string MyProperty
  2. {
  3. get { return _myProperty; }
  4. set
  5. {
  6. if (value != _myProperty)
  7. {
  8. _myProperty = value;
  9. NotifyPropertyChanged("MyProperty");
  10. // This line above could be improved by replacing the literal string with
  11. // a pre-processor directive like "#Property", which could be translated
  12. // to the string value "MyProperty" This new notify call would be as follows:
  13. // NotifyPropertyChanged(#Property);
  14. }
  15. }
  16. }
  17.  
  18. public static string MyPropertyPropertyName
  19. public string MyProperty {
  20. get { return _myProperty; }
  21. set {
  22. if (!String.Equals(value, _myProperty)) {
  23. _myProperty = value;
  24. NotifyPropertyChanged(MyPropertyPropertyName);
  25. }
  26. }
  27. }
  28.  
  29. // in the consumer.
  30. private void MyPropertyChangedHandler(object sender,
  31. PropertyChangedEventArgs args) {
  32. switch (e.PropertyName) {
  33. case MyClass.MyPropertyPropertyName:
  34. // Handle property change.
  35. break;
  36. }
  37. }
  38.  
  39. public static string GetNameOfCurrentMethod()
  40. {
  41. // Skip 1 frame (this method call)
  42. var trace = new System.Diagnostics.StackTrace( 1 );
  43. var frame = trace.GetFrame( 0 );
  44. return frame.GetMethod().Name;
  45. }
Add Comment
Please, Sign In to add comment