Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add ability to specify the access modifier of the property getter and setter. #416

Closed
Kiryuumaru opened this issue Sep 3, 2022 · 1 comment
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

Comments

@Kiryuumaru
Copy link

Overview

I cannot use the source code generator to generate the property getter or setter access modifier. I have to do it by implementing the property manually and calling the generated SetProperty.

API breakdown

An additional parameter for the ObservablePropertyAttribute to specify the access modifier of the property getter and setter.

Usage example

[ObservableObject]
public partial class Person
{
    [ObservableProperty(Setter = AccessModifier.Private)]
    string? phoneNumber;

    public void UpdatePhoneNumber(string phoneNumber)
    {
        if (SomeUtil.CheckPhoneNumberIsValid(phoneNumber))
        {
            PhoneNumber = phoneNumber;
        }
    }
}

Will generate

public partial class Person
{
    public string? PhoneNumber
    {
        get => phoneNumber;
        private set => SetProperty(ref phoneNumber, value);
    }

    public void UpdatePhoneNumber(string? phoneNumber)
    {
        if (SomeUtil.CheckPhoneNumberIsValid(phoneNumber))
        {
            PhoneNumber = phoneNumber;
        }
    }
}

Breaking change?

No

Alternatives

I manually implement the property

[ObservableObject]
public partial class Person
{
    string? phoneNumber;
    public string? PhoneNumber
    {
        get => phoneNumber;
        private set => SetProperty(ref phoneNumber, value);
    }

    public void UpdatePhoneNumber(string? phoneNumber)
    {
        if (SomeUtil.CheckPhoneNumberIsValid(phoneNumber))
        {
            PhoneNumber = phoneNumber;
        }
    }
}

Additional context

No response

Help us help you

Yes, but only if others can assist

@Kiryuumaru Kiryuumaru added the feature request 📬 A request for new changes to improve functionality label Sep 3, 2022
@Sergio0694
Copy link
Member

Duplicate of #291.

@Sergio0694 Sergio0694 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 3, 2022
@Sergio0694 Sergio0694 added duplicate 👥 Indicates that an identical issue or PR already exists mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit labels Sep 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants