I am programming vb.net. I would like to register everytime a property has been "set". But rather than create a Sub and call it from every property setter, I'd like it to be triggered automatically any time the setter is called. Is there any kind of "hookup" system I can use to achieve this?
Asked
Active
Viewed 38 times
-1
-
I don't believe there's any way to do this in a completely automated fashion for a property whose type is a primitive e.g. `Integer` or `Boolean`. If you have some sort of a wrapper object type, then you could overload assignment to also do whatever kind of a hook or event it is that you want. – Craig Mar 29 '19 at 13:40
1 Answers
0
There is an existing thread that explains how you can achieve this using the INotifyPropertyChanged Interface: Implementing INotifyPropertyChangedEvent

rwynn christian
- 59
- 4
-
But in that thread they actually make a call to a function inside the setter, which is what I want to avoid, the need to modify each and every setter to make the notification. – Amarnasan Mar 29 '19 at 11:20
-
It's not necessarily a function. It's an event. It notifies the calling object that a property from the current object is changed. To achieve what you want you will need to either create your own event or implement the INotifyPropertyChanged Interface. – rwynn christian Mar 29 '19 at 11:34
-
@rwynnchristian But the reply is correct: even with `INotifyPropertyChanged`, it's still necessary to add a function call in the setter to raise the event. – Craig Mar 29 '19 at 13:31