I have litle problem with PostSharp Implementation of INotifyPropertyChanged. PostSharp added PropertyChangedEventHandler PropertyChanged after compile time, but I need react from C# too.
Model a = new Model();
a.PropertyChanged += a_PropertyChanged;
Model implementation;
[NotifyPropertyChanged]
internal class Model
{
public string A { get; set; }
public string B { get; set; }
public string C { get { return string.Format("{0} - {1}", A, B); } }
}
I tried different ways to add handler,but unsuccessfully. Is there some way to do this?
Instance of class decorated by NotifyPropertyChanged can be casted to INotifyPropertyChanged at runtime:
((INotifyPropertyChanged)a).PropertyChanged
There is a helper method Post.Cast to avoid "Suspicious cast" warning:
Post.Cast<Model, INotifyPropertyChanged>(a).PropertyChanged += OnPropertyChanged;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With