Search code examples
c#roslyn-code-analysisroslynator

what is correct format for multiple discard variables in c# method


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)


Solution

  • 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