6

I have a method that is called by an external api that is expecting the method to have these specific parameters

        public static bool DoSomething(
            int x,
            int y
        ) =>
            true;

Rosyln code analysis is reporting an IDE0060 message as documented here

The exact message is

Warning IDE0060 Remove unused parameter 'y' if it is not part of a shipped public API

I replace 'x' with an '_'

what should 'y' be replaced with?

__ (double underscore) -- compiler complains that __ is not used (same IDE0060 message)

_ (single underscore) -- compiler complains that the parameter name _ is a duplicate (CS0100 error)

_1 (underscore followed by an number) -- compiler complains that _1 is an unused parameter (RCS1163 message)

James Bradt
  • 564
  • 5
  • 11
  • 1
    I believe this warning should be ignored/suppressed, not given credence, at least in this case. The parameter names are part of the public metadata. If there's a reason you have them and called them `x` and `y` (following a pattern across multiple classes, intended for future use, whatever), then it doesn't make sense to obfuscate them in this way (especially if it's for future use, where passing wrong/placeholder values will suddenly break the code when you implement it for real). I understand what the Roslyn team was going for here, but it's uninformèdly opinionated much of the time. – madreflection Feb 08 '21 at 18:35
  • Indeed, using two `_` parameters did not work until recently. But now it works: https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/discards – Alex Fainshtein Jun 26 '22 at 08:02

1 Answers1

8

it appears that there is a difference of opinion between the roslyn analyzer and the roslynator analyzer

roslyn - _1 is the correct discard parameter format

roslynator - __ is the correct discard parameter format

for now,

  • going with roslyn format,
  • supressing the roslynator message,
  • created an issue (#770) in the roslynator repo
James Bradt
  • 564
  • 5
  • 11