Recently I found that it is possible to auto-generate code for INotifyPropertyChanged
with the use of CommunityToolkit
. But I stubbed upon a problem.
I have a DTO class that is retrieved from the backend (and stored in shared project used by both FE and BE):
public class TrainingDayDurationDto {
public DateOnly Date { get; set; }
public short DurationMinutes { get; set; }
public TrainingDayDurationDto(DateOnly date, short durationMinutes) {
Date = date;
DurationMinutes = durationMinutes;
}
}
then on the frontend I map this DTO to client specific object that can have frontend specific functionality/properties added, so I have:
[INotifyPropertyChanged]
public sealed partial class TrainingDayDuration : TrainingDayDurationDto {
[ObservableProperty] private DateOnly _date;
[ObservableProperty] private short _durationMinutes;
public TrainingDayDuration(DateOnly date, short durationMinutes) : base(date, durationMinutes) {
}
}
I expected then auto-generated properties for TrainingDayDuration
will override those from parent object, but it doesnt seem to be the case. Because in debugger I can see 2x Date
and 2x DurationMinutes
properties like:
What is the right way to override it ? Or is there a better way how to approach this whole thing ?