Created
January 18, 2012 16:14
-
-
Save FelicePollano/1633791 to your computer and use it in GitHub Desktop.
notify property changed with expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PropertyChangeBase : INotifyPropertyChanged | |
| { | |
| protected void SignalChanged<T>(Expression<Func<T>> exp) | |
| { | |
| if (exp.Body.NodeType == ExpressionType.MemberAccess) | |
| { | |
| var name = (exp.Body as MemberExpression).Member.Name; | |
| PropertyChanged(this, new PropertyChangedEventArgs(name)); | |
| } | |
| else | |
| throw new Exception("Unexpected expression"); | |
| } | |
| #region INotifyPropertyChanged Members | |
| public event PropertyChangedEventHandler PropertyChanged = delegate { }; | |
| #endregion | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment