Skip to content

Add an analyzer for [field: ObservableProperty] uses #734

Closed

Description

@Sergio0694

The [ObservableProperty] attribute is only valid on field declarations. Trying to use it on a backing field for a property will not cause errors, as the source generator will simply skip that syntax node, but it will produce no diagnostics to tell the users what's wrong. There should be a new diagnostic analyzer to produce the appropriate diagnostic in these cases.

Example

Consider this snippet:

public partial class MyViewModel : ObservableObject
{
    [field: ObservableProperty]
    public string? Name { get; private set; }
}

This should emit a diagnostic on that attribute use.

Activity

  1. added
    feature request 📬A request for new changes to improve functionality
    analyzer 👓A new analyzer being implemented or updated
    on Jul 10, 2023
  2. self-assigned this
    on Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

analyzer 👓A new analyzer being implemented or updatedfeature 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