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

Option to enable required on a property generated by ObservableProperty #913

Closed
JochemPalmsens opened this issue Aug 17, 2024 · 2 comments
Closed
Labels
analyzer 👓 A new analyzer being implemented or updated feature request 📬 A request for new changes to improve functionality mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit

Comments

@JochemPalmsens
Copy link

Overview

Currently there is no option to add the required keyword to the property generated by the ObservableProperty. This is unwanted, because required is there for a reason: in many cases it's not correct for a property to ever be null[able] (The whole nullable/init/require stuff is really usefull in creating a safe application, so it would be weird not to support it).

So I suggest an option to enable required on the generated property is added.

API breakdown

[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
public sealed class ObservablePropertyAttribute : Attribute
{
    public bool IsRequired { get; set; }
}

Usage example

public sealed partial class MyType : ObservableObject
{
    [ObservableProperty(IsRequired = true]
    private string name;
}

Breaking change?

No

Alternatives

Alternatively? Maybe a separate attribute RequiredObservablePropertyAttribute?

Additional context

No response

Help us help you

Yes, but only if others can assist

@JochemPalmsens JochemPalmsens added the feature request 📬 A request for new changes to improve functionality label Aug 17, 2024
@Sergio0694
Copy link
Member

Closing this, superseded by #555.

@Sergio0694 Sergio0694 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 20, 2024
@Sergio0694 Sergio0694 added mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit analyzer 👓 A new analyzer being implemented or updated labels Aug 20, 2024
@JochemPalmsens
Copy link
Author

Ah, and now see it's a dupe of #679
thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer 👓 A new analyzer being implemented or updated 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