As resharper 5 now has DIY patterns, what patterns have you writen that fix coding idioms that you've seen? Is there an online resharper pattern repository? I thought here would be a logical place to vote for your favorite patterns.
I think of this as programming in the small.
I'm currently doing a deep refactoring in a legacy application. Here are some ReSharper (6.1) patterns I'm using to fix some code issues:
Search pattern:
$type$ $var$ = $expr$;
$stmt$
$var$.Dispose();
$var$ = null;
Replace pattern:
using (var $var$ = $expr$)
{
$stmt$
}
Search pattern:
$type$ $var$ = $expr$;
$stmt$
$var$.Dispose();
$var$ = null;
return $something$;
Replace pattern:
using (var $var$ = $expr$)
{
$stmt$
return $something$;
}
Resharper does not recognize the following opportunity of using the ??
operator, so I've created a pattern for it. Of course, it makes a conditional assignment become a simple assignment (to the same value when the $nullable$
is not null); still, I find the resulting code to be easier on the eye.
Search pattern:
if (!$nullable$.HasValue) $nullable$ = $value$;
Replace pattern:
$nullable$ = $nullable$ ?? $value$;
And, finally, one of my favorites:
Search pattern:
$str1$.Equals($str2$)
Replace pattern:
$str1$ == $str2
No full-fledged online SSR pattern catalog exists though we wish there was one. This is definitely in a to-do list for the future. However, on the ReSharper documentation page, there's a link to a sample Pattern Catalog based on patterns used in ReSharper team.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With