dotnet / dotnet/format

CA1822 mistakenly triggers on partial class

Open
#1,922 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
1.9k
Forks
173
Avg merge
10d 13h
Merged PRs (30d)
1

Description

If you have a C# class, then rule CA1822 can incorrectly be flagged for a method which accesses a field defined in a separate file.

Example:
D:\projects\ConceptReader\testbed\catcher\liveview\MainWindow.xaml.cs(39,21): info CA1822: Member 'WriteLine' does not access instance data and can be marked as static [D:\projects\ConceptReader\testbed\catcher\liveview\liveview.csproj]

```
public void WriteLine(string message)
{
Trace.WriteLine(message);
statusText.Text = message;
}
```

However, statusText is an internal field in the machine-generated MainWindows.g.i.cs partial class. This doesn't seem to be picked up by dotnet format and so it is happy to rewrite the WriteLine code to make it static, which doesn't compile anymore.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.