SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
GNU Lesser General Public License v3.0
781 stars 226 forks source link

Fix S1694 FP: Abstract class with field or constructor #9494

Closed paulhickman-ec closed 2 months ago

paulhickman-ec commented 3 months ago

Description

The code below triggers S1694. However, in the case where there is logic using the constructor arguments in the abstract class, it should not be converted to an interface.

Repro steps

public abstract class Foo
{
    protected int _data;

    protected Foo(int data)
    {
        _data = data * 2;
    }

    public abstract void Bar();
}

Expected behavior

S1694 should not fire as the constructor argument/code makes it unsuitable to convert to an interface. This code could be quite complex and should be shared between all subclasses.

Actual behavior

S1694 does trigger.

Known workarounds

Suppress the issue.

Related information