Fody/PropertyChanged

Have On_property_Changed events also deliver the old value with special signature

Closed this issue · 5 comments

The On_property_Changed is very useful when adding property changed watchers when a property has changed.

Unfortunately the same mechanism cannot be used to unregister the previous delegate attached to the previous object.

It would be nice if we could either extend On_property_Changed so that when given with a signature such as:

void OnNameChanged(string oldValue)

it would provide the old value as well so we could undo whatever was done to that property before.

Probably it would need to be a nullable to also support value types.

Example:

class A {
   public SomeOtherClass Classy { get; set;}

   private OnClassyChanged(SomeOtherClass old){
      if (old != null) {
          old.PropertyChanged -= WatchChanges;
      }

      if (Classy != null) {
          Classy.PropertyChanged += WatchChanges;
      }
}

It seem that this feature is already supported although undocumented. I discovered this works by looking at the code when I wanted to implement this.

Can the Wiki page on OnPropertyChanged be updated to show this feature? I would do that if I could edit the page.

what changes would u like done?

As a reminder to myself:

void On_properyName_Changed(object old, object new)

is the current expected signature.

Could the signature maybe be changed to actually provide typed values? I mean they are known from the proerty.

Hmm, yes the code currently requires object parameters. I don't know why, from a quick glance at the code it doesn't seem this would be too hard to change, but I may be wrong.

I had this in my "private backlog" for quite a while, but now found some to look at this.