Visibility modifier for [ObservableProperty] Source Generator #668
Labels
duplicate 👥
Indicates that an identical issue or PR already exists
feature request 📬
A request for new changes to improve functionality
mvvm-toolkit 🧰
Issues/PRs for the MVVM Toolkit
Overview
There is currently no way to modify the visibility of the property setter of a generated property. There are sometimes situations where you would mark a setter as
internal
,private
orprotected
(or eveninternal protected
), so that a property can only be set by certain actors, while the getter should always bepublic
, so that it can be used in binding expressions.For example, it would be useful if the
[ObservableProperty]
Source Generator would be able to generate the equivalent of the following:The
Identifier
property could then still be used in a binding expression:The value can only be set from inside the class, e.g. in a method or command that calls some API:
This is useful, for example, if the value of the
Identifier
comes from an API call and shouldn't be publicly settable, or when it should not participate in Two-Way bindings. Therefore there should be a way to modify the visibility.API breakdown
My proposal is to add an optional visibility modifier to the
[ObservableProperty]
Source Generator calledSetterVisibility
which takes a single argument, e.g. an enum value or some other limited form of identifier:The resulting properties should then be equivalent to the following:
The default will either be
Visibility.Public
ornull
which will avoid breaking existing behavior.Usage example
MyViewModel
MyView.xaml
Breaking change?
No
Alternatives
n/a
Additional context
No response
Help us help you
Yes, but only if others can assist
The text was updated successfully, but these errors were encountered: