You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Warning CA1822 Is “‘xxx’ does not access instance data and can be marked as static”, the problem is that if (as in my case) xxx happens to be a public property used by XAML marking it as static will break the connection to XAML and indeed the documentation for CA1822 points out that if xxx is public marking it static may be a breaking change.
It would be nice if I could tell it to ignore this warning for public properties, but I could not figure out how, so I set out to suppress the property in the source. The trouble is, doing that generates IDE0079 “Remove unnecessary suppression” and it’s not clear to me what’s unnecessary about this suppression.
This only becomes more challenging when you are dealing with a large body of code (I was refactoring 14,000 lines) and there are many such warnings, some actionable, some not.
There's a sample MAUI project using MVVM to illustrate the problem at https://github.com/david-maw/Warning.git, run it and tap the button to change the message.
The message comes from a string property which reads a static string, the button command invokes OnPropertyChanged to notify the page to update the displayed string.
The property definition is easy enough to change to
Warning CA1822 Is “‘xxx’ does not access instance data and can be marked as static”, the problem is that if (as in my case) xxx happens to be a public property used by XAML marking it as static will break the connection to XAML and indeed the documentation for CA1822 points out that if xxx is public marking it static may be a breaking change.
It would be nice if I could tell it to ignore this warning for public properties, but I could not figure out how, so I set out to suppress the property in the source. The trouble is, doing that generates IDE0079 “Remove unnecessary suppression” and it’s not clear to me what’s unnecessary about this suppression.
This only becomes more challenging when you are dealing with a large body of code (I was refactoring 14,000 lines) and there are many such warnings, some actionable, some not.
There's a sample MAUI project using MVVM to illustrate the problem at https://github.com/david-maw/Warning.git, run it and tap the button to change the message.
The message comes from a string property which reads a static string, the button command invokes OnPropertyChanged to notify the page to update the displayed string.
The property definition is easy enough to change to
The corresponding change to the XAML is trickier, because you must find it, but something like this works to display a message using a label control:
Unfortunately, clicking the button will no longer change the text because
OnPropertyChanged
no longer notifies the page.The only workaround I've found is to disable the warning globally, but that seems a bit drastic.
The text was updated successfully, but these errors were encountered: