CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
2.99k stars 294 forks source link

Add support for setter protection level for ObservableProperty #758

Closed sensslen closed 1 year ago

sensslen commented 1 year ago

Overview

When using the [ObservableProperty] attribute to generate the code for the observable property, the protection level of the generated setter is always public

API breakdown

public enum SetterProtection
{
    Public,
    Protected,
    Private
}

[ObservableProperty(SetterProtection = SetterProtection.Private)]
private int _someValue;

Usage example

[ObservableProperty(SetterProtection = SetterProtection.Private)]
private int _someValue;

Breaking change?

No

Alternatives

I am not aware of any

Additional context

I do quite often want to provide readonly properties for binding in xaml. These properties should not be set from xaml. While I can make sure this is how things are done, I don't get any support from the Toolkit (and if the xaml is wrong and sets such a property, It will silently work instead of causing a binding error).

Help us help you

Yes, but only if others can assist

Sergio0694 commented 1 year ago

Duplicate of #291. Superseded by #555.