/ Published in: C#
The only way i know to create a normal "fire property changed" method that is still efficient yet strongly typed. The other common pattern uses run time checking and uses the TyepDescriptor for the current type to check for property existence - a much less elegant solution imho.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public class PresenterBase : INotifyPropertyChanged { private string _myProperty; public string MyProperty { get { return _myProperty; } set { _myProperty = value; OnPropertyChanged(() => MyProperty); } } protected virtual void OnPropertyChanged<T>(Expression<Func<T>> propertyEvaluator) { var lambda = propertyEvaluator as LambdaExpression; var member = lambda.Body as MemberExpression; var handler = PropertyChanged; if (handler != null) { } } #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; #endregion }