0

I have the following recursive function in C# which has a parameter named "format" which is never used outside of the recursive call.

public static int MyFunction(int c, bool format = false) 
{
   if(....) 
   {
       MyFunction(c - 1, format);
   }
   ....
   return ...;
}

Can I ask resharper to provide me a warning about that, so that it tells me the parameter is dead? In my case, I got an error because I forgot to pass format to a sub-function. Having a warning would have helped me not to loose time debugging.

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
Mikaël Mayer
  • 10,425
  • 6
  • 64
  • 101
  • 1
    It's public method, it could be called by any code that references the assembly it is in, so resharper cannot determine it is unused, just that nothing within the current solution uses it. – Ben Robinson Sep 26 '14 at 12:38
  • I don't see why Resharper couldn't warn against it, public or not. So I don't think making it private will make Resharper notice the problem. – Patrice Gahide Sep 26 '14 at 12:44
  • 1
    @PatriceGahide Interestingly if you make the method private you get "Parameter format is only passed to itself". I think the issue is that changing the signature on a public method is a braking change. Basically Resharper is saying "you can get rid of this" not "hey why aren't you using this". – juharr Sep 26 '14 at 12:45
  • 1
    @juharr Interesting indeed. I understand but I don't fully agree. Just for the sake of preserving the API, R# don't even _suggest_ to take a look at that unused parameter? And as for the OP's question, that doesn't seem to be configurable. – Patrice Gahide Sep 26 '14 at 12:59
  • **Solution-Wide Error Analysis** will warn about this, if you turn it on. With the 'pass through' code, you get "parameter is only passed to itself"; without that, you get "parameter is never used". – AakashM Sep 30 '14 at 10:42

0 Answers0