Is there an alternative to delegated properties fo...
# announcements
c
Is there an alternative to delegated properties for observing changes to all properties on a class? Even a hacky reflection-driven way would be fine... Right now, I'm having to add the delegate to every single property and it's easy to miss one (especially in subclasses)
l
You can write a custom generic delegate (plus for primitive types if you have to avoid autoboxing overhead) that takes as a parameter something that will notify observers, and use this delegate for all of your properties. Unfortunately, there's no way to enforce it on subclasses other than documentation
c
Thanks for the suggestion. I ended up going in a similar direction, and although it’s not ideal to be able to accidentally forget to add the delegate to a property, it’s working pretty well.
👍 1