Private class methods used by reference produce a false positive for S1172.
internal class Program
{
public static void Main(string[] args)
{
CallDelegate(new MyClass("Some name").Method);
CallDelegate(SomeImplementingMethod);
}
private delegate void MyDelegate(object o);
private static void CallDelegate(MyDelegate d)
{
d(1);
}
private static void SomeImplementingMethod(object o)
{
Console.WriteLine(o);
}
private class MyClass
{
private readonly string _name;
public MyClass(string name)
{
_name = name;
}
public void Method(object o)
{
Console.WriteLine(_name);
}
}
}
- SonarLint 6.3.1.40498
- .NET Framework 4.7.2
- Jetbrains Rider 2021.3.1