Replies: 2 comments 1 reply
-
|
This would be a great thing to have in the base library to further reduce boilerplate code. I had to roll a similar solution in a project I am working on (minus auto-detection). The first iteration looked just like what you proposed but then it evolved to also "hook" into other INPC implementations with support for updating references: The generated code looked roughly like: |
Beta Was this translation helpful? Give feedback.
-
|
With the current library, surely the simplest approach is to add However, I do think it would be nice to have an attribute on the dependent property, even if you had to manually list the properties it depends on: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Add a
[ComputedProperty]attribute (alongside[ObservableProperty]) to support read-only, computed properties that automatically raisePropertyChangedwhen any of their observable dependencies change — with zero manual wiring codeMotivation / Problem
Today, derived MVVM properties require tedious manual boilerplate:
// Current approach
[ObservableProperty] public partial string FirstName { get; set; }
[ObservableProperty] public partial string LastName { get; set; }
// Must repeat for every dependency, on every computed property
partial void OnFirstNameChanged(string? _) => OnPropertyChanged(nameof(FullName));
partial void OnLastNameChanged (string? _) => OnPropertyChanged(nameof(FullName));
public string FullName => $"{FirstName} {LastName}";
Beta Was this translation helpful? Give feedback.
All reactions