Observable auto properties #3910
Replies: 3 comments 1 reply
-
Have you checked out Source Generators yet? |
Beta Was this translation helpful? Give feedback.
-
Related: #1074 Also, #133 and #140 are being investigated for C# 10. With #133, your boilerplate would look like this: public string FirstName
{
string field;
get => field;
set
{
field = value;
OnPropertyChanged(nameof(FirstName));
}
} And if you have a protected public string FirstName { string field; get => field; set => Set(ref field, value); } With #140, this would shrink even further: public string FirstName { get; set => Set(ref field, value); } |
Beta Was this translation helpful? Give feedback.
-
The key reason preventing this should be that .NET runtime doesn't have a standard way for change notification. There are ways in app models, so the sugar should be at app model level (generators), not fundamental level. |
Beta Was this translation helpful? Give feedback.
-
This is a proposal to add an observable keyword to auto properties. This keyword would be a shorthand way for implementing property change notification.
The exact details of how it would implement the property change notification aren't completely hashed out, but this is one idea (FirstNameChanged event + OnFirstNameChanged method)
Another obvious way is implementing INotifyPropertyChanged, but that would be very invasive to the type. Possibly an implicit pattern could be used instead.
Beta Was this translation helpful? Give feedback.
All reactions