❔ Listening for object properties changed
let's say i have a object:
i would like to attach an event listener automatically for its all properties so if i do
foo.Counter++;
some method will invoked without manually adding code to every property
10 Replies
your only way afaik
i want to avoid this
i dont think that's possible
i need it to get delta change between previous and current state of object
these data i want to send across network so i want to avoid sending data that has not changed
the idea is to get know which properties changed and send only these which changed
well you can probably do it with some system reflection shenanigans
perhaps i could store old value as hashcode and then compare them
has a different idea, make a method to change state, ChangeState(x => x.Counter, 2)
yeah that could work
"changeState" will know Counter change, it will immediately schedule a task to update client state but if another state change in next 10ms then cancel previous synchronization, that way 3 changes of same property will yield a single update
Is this a viewmodel for some ui?
Because it sounds like what you want is INotifyPropertyChanged and CommunityToolkit.Mvvm, which has source generators to generate the boilerplate for you
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.