Operating system: Windows 10
SonarLint plugin version: 250.944
Programming language you’re coding in: C# latest & .Net 8 preview 6
Is connected mode used: No
IDE0290 suggests changing the following to use a primary constructor:
public sealed class Data : IParseSegment
{
private readonly int _length;
public readonly int Start;
public int Length => _length & int.MaxValue;
public Data(int start, int end)
{
Start = start;
_length = end - start + 1;
}
}
Here’s the updated version:
public sealed class Data(int start, int end) : IParseSegment
{
private readonly int _length = end - start + 1;
public readonly int Start = start;
public int Length => _length & int.MaxValue;
}
Sonarlint wants to move the two member initializers = end - start + 1
and = start
. This is obviously incorrect, and doing so triggers CS9113.