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.8k stars 277 forks source link

Add an option to [ObservableProperty] - generate a private setter #840

Closed stepagrus closed 4 months ago

stepagrus commented 4 months ago

Overview

Hello!

I need a private setter when generating an observable property.

For example:

  [ObservableProperty(privateSetter: true)]
  private bool _isValid;

Will generate the following code (code simplified to make it easier to read):

public bool IsValid
{
    get => _isValid;
    private set
    {
        if (EqualityComparer<bool>.Default.Equals(_isValid, value))
        {
            _isValid = value;
            OnPropertyChanged();
        }
    }
}

API breakdown

no breakdowns

Usage example

  [ObservableProperty(privateSetter: true)]
  private bool _isValid;

Breaking change?

No

Alternatives

-

Additional context

No response

Help us help you

Yes, but only if others can assist

Sergio0694 commented 4 months ago

Duplicate of #291. Superseded by #555.

stepagrus commented 4 months ago

Thank you. We will wait for partial properties to be delivered