Skip to content

Add support for "required" and "virtual" keywords to property generator #679

Closed as not planned

Description

@michael-tlsoftware

Overview

When working with nullable libraries, being able to add the required keyword to properties is helpful. I have reviewed the source generator and dont believe this is currently supported when using ObservablePropertyAttribute . I propose adding properties to the this class to signal to the generator to add this modifier where required. This would default to false to not impact existing usage.

As the code would be similar, I propose to add the virtual modifier at the same time for completeness.

API breakdown

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

Usage example

[ObservableProperty(Required = true, Virtual = true)]
bool _myProperty;

Breaking change?

No

Alternatives

Current alternative is to selectively use source generator, and use the underlying methods when creating properties by hand.

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item

Activity

  1. Sergio0694 commented on May 1, 2023

    @Sergio0694
    Member

    Duplicate of #291.
    Superseded by #555.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature request 📬A request for new changes to improve functionalitymvvm-toolkit 🧰Issues/PRs for the MVVM Toolkit

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions