Skip to content

Allow custom property attributes for [ObservableProperty] #413

@Sergio0694

Description

@Sergio0694

Overview

Right now, it's not possible to specify property attributes when using [ObservableProperty], which has been a pain point for some users, as it forces you to go back to manual properties in that case. There's been several asks for this in the past, see (#228, #217, #208). We could technically support this via the explicit property: target, which Roslyn ignores but doesn't block. That is:

[ObservableProperty]
[property: JsonPropertyName("name")]
private string? name;

The generator would emit:

[JsonPropertyName("name")]
public string? Name
{
    get => name;
    set => ...
}

This would effectively allow users to have perfect control over attributes on target properties.

Note: Roslyn will currently emit a diagnostic in this case, so users would have to suppress it or just ignore it. Just not the perfect tooling experience, but it would still solve the issue and be a valid solution for now with no language changes needed. which we can automatically suppress with a dedicated diagnostic suppressor, so not a problem.

Metadata

Metadata

Assignees

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