Unused method parameter for a private class method used with method reference

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

Hi @phillib0,

As far as I can tell this is not a false positive. The issue is raised on this method:

public void Method(object o)
{
    Console.WriteLine(_name);
}

and inside this method, the o parameter is not used.

This topic was automatically closed after 5 days. New replies are no longer allowed.