I am trying to add a Resharper template to the template directory to compare strings. In the end, I would like him to warn me when I jump into a code like string1 == string2 and suggest replacing it with string1.Equals(string2, StringComparison.OrdinalIgnoreCase) . From here I can change it to the appropriate case, but the initial step of enforcing the use of Equals with comparison options makes the intention of comparison obvious.
I can do this by creating a search pattern:
$string1$ == $string2$
And creating a Replace template:
$string1$.Equals($string2$, StringComparison.OrdinalIgnoreCase)
Where both $ string1 $ and $ string2 $ are expressions of the type "String (or derived type)". This is a great start, because even if I wanted it to be case sensitive, I can see the options and change them.
The problem I am facing is that now it also warns me about string == null . Is there a way to make a null exception in a search?
source share