Just found out this even existed this morning. First thing I did was try to make sure null or constants were always on the left side of an equality check, to prevent unintentionally setting an object to null.
I haven't figured out constants yet, but null checking was:
Search pattern: if($expr$ == null) $stmt$
Replace Pattern: if(null == $expr$) $stmt$
Placeholders:
expr: expression of type System.Object (or derived type)
stmt: minimum of one statement, no maximum
Then I copied that pattern and made a simple Find-only pattern:
Search pattern: if($expr$ = null) $stmt$
Placeholders:
expr: expression of type System.Object (or derived type)
stmt: minimum of one statement, no maximum
This one will actually find any instances where you did set something to null in an if statement, whether you meant to or not.
I'm seriously about to lose a few days writing patterns. My software will be better for it, though.
EDIT: Here's another one that irritates me in my code base. Since Directory.CreateDirectory checks for the existence of the directory internally, there's no sense in making a redundant call to Directory.Exists beforehand.
Search pattern:
if (!Directory.Exists($path$))
{
Directory.CreateDirectory($path$);
}
Replace Pattern:
Directory.CreateDirectory($path$);
Placeholders:
path: identifier