Search code examples
c#cryptographyresharperoptional-parametersnamed-parameters

Should these arguments be added or removed?


When Resharper argues with itself, how does one know which persona to give more credence?

I think I have found some code that does confuse Resharper (this is apparently a very unusual case - after using it for a day, I think Resharper is the bee's knees/the greatest thing since liquified bread, etc.).

With this line of code:

ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));

Resharper tells me to "add argument name 'rgbkey'" and then "add argument name 'rgbIV'"

So that the line is then:

ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(rgbKey: SecretKey.GetBytes(32), rgbIV: SecretKey.GetBytes(16));

When I run Resharper again, though, it says,

"Redundant argument name specification" - "Remove argument name specification" (rgbkey) (and then rgbIV).

It seems either way works fine, though...


Solution

  • Explicit parameter naming is optional on mandatory parameters, so both forms are "correct," the question is which do you like better? Like vcsjones said, Resharper is just giving you some refactoring options to suit your preferences.