Skip to content

ObservablePropertyAttribute on a field: avoid CS0169? #375

@chucker

Description

@chucker

I made a simple INPC property like so:

[ObservableProperty]
private bool _IsReadOnly;

As expected, I can now bind to IsReadOnly in XAML. Great! However, VS now shows me a warning:

Severity    Code    Description Project File    Line    Category    Suppression State
Warning CS0169  The field 'MyViewModel._IsReadOnly' is never used MyProject   MyViewModel.cs  148 Build   Active

Makes sense; it doesn't understand that the field exists only for the generated code. However:

  1. is that the expected behavior?
  2. even if I wrap the field in #warning pragma disable CS0169, the warning doesn't go away. Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions