Skip to content

Instantly share code, notes, and snippets.

@FelicePollano
Created January 18, 2012 16:14
Show Gist options
  • Select an option

  • Save FelicePollano/1633791 to your computer and use it in GitHub Desktop.

Select an option

Save FelicePollano/1633791 to your computer and use it in GitHub Desktop.
notify property changed with expression
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