Search pattern for arguments with certain modifiers (ref, out, etc) Follow
I'd like to build a search pattern to find methods that include parameters with certain modifiers. For example, there is an anti-pattern in some of the code that I am working on that unnecessarily uses a lot of out parameters. Is there a way to set up a search pattern to find methods that are declared like this? I'd also be curious to see if I could find methods defined using generics in a certain way. I'm not sure if the search with pattern feature can do this. It seems to be more about just finding code patterns rather than methods declared in a certain way.
Please sign in to leave a comment.
You could just use Find in Files with a regular expression. Search for something like \(.*(out>|ref>).*\).
It's not as handy as the Pattern search in Resharper, but it will quickly show you everywhere in your code that someone is using an our or ref parameter. It basically finds all complete words 'out' and 'ref' inside of paranthesis. Obviously it doesn't differentiate between a method call and a method definition.
If there is a way to do this using pattern search, I don't see it.
Try such pattern:
where
method, arg - identifier placeholder
args1, args2 - argument placeholders
type - type placeholder
That seems to be pretty close to what I want. Unfortunately I get "Can not parse pattern" when trying to use it. Maybe I'm not setting the placeholders up properly?
Which ReSharper version do you use?
There is a known problem in R# 5, that appears from time to time. Please, try ReSharper 6 EAP builds.
I'm using ReSharper 5 right now. I'm not quite ready to make the jump to 6 yet. I guess this is just a bug in version 5?
Unfortunately, yes.