You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That uses the automatic property dependency stuff, and a PropertyChanged event for FullName will be raised whenever FirstName or LastName changes. If you need to use a method to generate the value for FullName, you can do:
[Notify]privatestring _firstName;[Notify]privatestring_lastName;[DependsOn(nameof(FullName), nameof(LastName))] public string FullName => CreateFullName();
(or the equivalent using AlsoNotify).
These both have the advantage of letting FullName say what it depends on, rather than forcing you to manually keep track of this.
The downside is that you don't cache the value of FullName and it's re-calculated on each access, but I'd love to see a case where that actually mattered!
Fair enough. I can't promise when I'll get time to look at this, it might be a few weeks.
If you fancy having a crack yourself, OnPropertyNameChanged will need to change to a List<OnPropertyNameChangedInfo>, and FindPropertyNameChangedMethod updated to find multiple methods to call, using a new attribute.
For the attribute name, I'm not sure whether to go with your PropertyChangedHook (which does match the wording in the README), or something like OnChanged...
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Currently, property hook work like:
If the
FullName
depends on more properties, theOn{PropertyName}Changed()
list may grow unnecessary.And the property hook is hard to detect errors in compile-time if we try to rename the
_firstName
.What if we can use attributes, it can be:
Beta Was this translation helpful? Give feedback.
All reactions