Resharper C# bug: [PublicAPI] prevents "field can be made readonly" warning for private fields.
Consider the following code:
public sealed class Test
{
private int _value;
public Test(int value)
{
_value = value;
}
public int Value => _value;
}
Resharper will correctly suggest that the _value can be made readonly.
However, if you decorate the class with [PublicAPI] the warning incorrectly goes away. I don't think that the warning should go away for a private field that can be made readonly.
This is an issue because you have to decorate public classes in class libraries with [PublicAPI] otherwise you get annoying warnings about public items not being used, or suggestions to make public items private - but doing so stops suggestions about making private fields readonly.
Note that if you decorate a class with [PublicAPI] and afterwards add a parameter to a constructor, Resharper will offer to add a private readonly backing field for it, so that at least is (correctly) ignoring the [PublicAPI] attribute.
Please sign in to leave a comment.
Hello Matthew,
Please ignore the previous message.
There's similar request reported - https://youtrack.jetbrains.com/issue/RSRP-339368.
You are welcome to comment or vote for it.
Thank you.