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.
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 explicitproperty:target, which Roslyn ignores but doesn't block. That is:The generator would emit:
This would effectively allow users to have perfect control over attributes on target properties.