- Language: C#
- Rule: S1172
- Product: SonarQube for Visual Studio 8.12.0.12239
- IDE: Visual Studio Community 2022 17.13.2
- Connected mode: No
The rule S1172 (“Unused method parameters should be removed”) is triggered when a parameter is actually used in a local function with null-conditional or null-coalescing operators. For example, here text
and action
trigger the rule, but they are used in the local function Do
:
public class MyClass
{
private void SomeMethod(string text, Action action) // False-positives for "text" and "action"
{
Do();
void Do()
{
Console.WriteLine(text ?? "Nothing");
action?.Invoke();
// If these are enabled, the rule does not trigger:
// Console.WriteLine(text);
// action();
}
}
}