In my last post, I covered the implementation of INotifyPropertyChanged interface when using SheepAspect as an AOP library. In the end, I also implemented an approach to notify changes of computed read-only properties. This approach has a downside, the dependent properties discovering process must be done in run-time.
Such a journey recalls us that Catel.Fody didn’t have support for notifying property changes of computed read-only properties. How could such a thing ever be possible? Obvious, “the shoemaker's son always goes barefoot” ;). But don’t worry: the feature is here, moving the dependent properties discovering process to build-time, thanks to Fody.
public string FirstName { get; set; }
will be weaved into
public string FirstName { get { return GetValue<string>(FirstNameProperty); } set { SetValue(FirstNameProperty, value); } } public static readonly PropertyData FirstNameProperty = RegisterProperty("FirstName", typeof(string));
But now we added a new feature to Catel.Fody. If a read-only computed property like this one exists:
public string FullName { get { return string.Format("{0} {1}", FirstName, LastName).Trim(); } }
the OnPropertyChanged method will be also weaved into
protected override void OnPropertyChanged(AdvancedPropertyChangedEventArgs e) { base.OnPropertyChanged(e); if (e.PropertyName.Equals("FirstName")) { base.RaisePropertyChanged("FullName"); } if (e.PropertyName.Equals("LastName")) { base.RaisePropertyChanged("FullName"); } }
This feature is already available in the latest beta package of Catel.Fody.
Try yourself and let us know.
It's very handy.
ReplyDelete