question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Have On_property_Changed events also deliver the old value with special signature

See original GitHub issue

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;
      }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tom-englertcommented, Jun 4, 2021

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

0reactions
ltrzesniewskicommented, May 27, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Handling OnPropertyChanged
The event handler provided, has to have the signature of the PropertyChangedEventHandler delegate. This signature is:
Read more >
Proposal: Add OldValue and NewValue properties in ...
PropertyChanged event of a model from another view model, e.g. logging of property changes of the model from the view model. Current ...
Read more >
DependencyPropertyChangedEv...
This delegate is the handler signature for particular events that report dependency property changes. An event that uses this handler is exposed as...
Read more >
Event-Driven Programming :: K-State CIS 400 Textbook
To do so, we need both a name for the event, and a delegate. In C# a Delegate, a special type that represents...
Read more >
Attached Properties - What Are They Good For? - Code Mill Matt
An attached property is a special type of bindable property, ... it's signature receives the view it is attached to – the old...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found