Why keywords not permitted in Search patterns? Follow
I'm curious why I can't put keywords into a R# search pattern. For example, I'd like to do a search & replace from this:
foreach ($type$
To this:
foreach (var
But the search pattern dialog tells me that the expression can't be parsed if I type "foreach". Whereas "foreac" is fine. This leads me to believe that keywords are not allowed in the search pattern.
Is there a way around this?
Please sign in to leave a comment.
Hello Scott,
Please note that you should specify full language construct so that SSR could
parse it. For instance replace
foreach($type$ $v1$ in $v2$)
{
$stmt$
}
with
foreach(var $v1$ in $v2$)
{
$stmt$
}
works fine for me. Let me know if this helps. Thank you!
Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
Oh, cool. Ok, then can I add a feature request? :) It would be useful to have more information than "Search pattern could not be parsed" on a problem with the search pattern. I end up just guessing at what I did wrong.
Also: the pattern works, but it appears to work too much. I used your example (though I removed the braces), and set 'type' as a type, 'v1' as an identifier, 'v2' as an expression, and 'stmt' as any number of statements. I set it to be a warning. It works perfectly on this:
foreach (int i in new[] { 1, 2, 3 })
{
Console.WriteLine(i);
}
But when I replace that int with a var, I still get the warning. So apparently 'var' is considered a type in the search pattern, somehow?