How to flatten the entire project for "Remove Overcapture" with Resharper?
I am dealing with a large old codebase that has many like this:
try
{
...
}
catch
{
throw;
}
Resharper favorably notes this and offers the "Remove excess catch" option, but I don't like going one by one, I would like to destroy them all at once. Is there a way to do this with Resharper, perhaps integrating it with Code Cleanup?
+2
a source to share
1 answer
If you are using Resharper 5.0 you can import the following template (save it as xml file) into Template Directory (Resharper> Tools> Folder Directory> Import) then run Search Now to find all instances so you can browse and select for them replacement.
<CustomPatterns>
<Pattern Severity="HINT">
<Comment>useless catch</Comment>
<ReplaceComment>remove useless catch</ReplaceComment>
<ReplacePattern>$code$</ReplacePattern>
<SearchPattern><![CDATA[try
{
$code$
}
catch
{
throw;
}]]></SearchPattern>
<Params />
<Placeholders>
<StatementPlaceholder Name="code" Minimal="1" Maximal="-1" />
</Placeholders>
</Pattern>
</CustomPatterns>
The sample worked on my test code. I don't know how the pattern matching mechanism handles whitespace, so you might have to change tabs to whitespace or whatever matches your code standard.
+5
a source to share