1

Suppose you have 1000 methods in your solution. You want to do some refactoring by finding methods with common signatures and refactoring them. Is there a standardized method of doing this? How do you find methods with common signatures or at least 2 of the parameters match?

Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062
  • you can use http://www.ndepend.com/ and then write a query to find all methods contains two or more parameters. FYI it uses linq syntax so its very easy to do that – adeel41 May 22 '16 at 16:49

1 Answers1

1

Yes it's possible! Go to ReSharper - Options - Find - Search with Pattern and create a pattern similar to:

enter image description here

public void $method$($type$ $name$)
{
    $st$
}

One more example: Resharper custom patterns change method name.

Hint: try Argument Placeholder if you don't want to specify exact method's signature.

EDIT: How to combine more than one pattern in your search? The workaround: test and save each pattern one by one. Then go to ReSharper - Options - Code Inspection - Custom Patterns. Here you should see all patterns you saved before. Set each pattern's severity (dropdownbox) to Error and then go to ReSharper - Inspect - Solution Errors window. Turn on Solution wide analysis and occurrences of any pattern will be highlighted as errors in this window.

Community
  • 1
  • 1
Ilya Chumakov
  • 23,161
  • 9
  • 86
  • 114
  • this is awesome, but i cannot get it to work. for example: – Alex Gordon May 23 '16 at 17:20
  • @l--''''''---------'''''''''''', set `name` as `identifier` instead of `argument`. – Ilya Chumakov May 23 '16 at 18:13
  • thank you. here are the results. im not sure i understand what this means? http://i.imgur.com/HzoaYMN.png – Alex Gordon May 23 '16 at 19:32
  • i think i understand! let's say i wanted to search for an int and a string and i wanted it to not pay attention to the order: http://i.imgur.com/LvZmPNz.png somethin glike that, but i would want it to also find: http://i.imgur.com/LwpIZFf.png --- you see how the signature is reversed? – Alex Gordon May 23 '16 at 19:34
  • @l--''''''---------'''''''''''', as I understand, you look for the `OR` statement. Unfortunately, I know only the workaround: try to create two patterns and then combine them in one search. I've updated my answer with details. – Ilya Chumakov May 23 '16 at 20:09
  • unable to search, am i doing something wrong with my syntax? http://i.imgur.com/FLZEOkP.png http://i.imgur.com/AMGlhWQ.png – Alex Gordon May 23 '16 at 20:26
  • @l--''''''---------'''''''''''', it looks like a bug. Could you edit this pattern by double-click? – Ilya Chumakov May 23 '16 at 20:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/112714/discussion-between-l-and-ilya-chumakov). – Alex Gordon May 23 '16 at 20:33