Why doesn't this replacement structured pattern work?
Why doesn't this find/replace structured pattern work?
I am trying to match this code:
public bool SetPandGValue( byte[] pValue, byte[] gValue )
{
try
{
ic.CreateDHDestinationServiceProvider( pValue, gValue );
return true;
}
catch( Exception ex )
{
string temp = ex.ToString();
return false;
}
}
My pattern is (the xml from the resharper.user file):
<Pattern Severity="HINT">
<Comment>There is no need to call ToString, moron.</Comment>
<ReplaceComment>Remove the unnecessary temp string.</ReplaceComment>
<ReplacePattern><![CDATA[try { $trystatements$ }
catch (Exception $ex$)
{
$remainingcatchstatements$
}]]></ReplacePattern>
<SearchPattern><![CDATA[try { $trystatements$ }
catch (Exception $ex$)
{
string $tmpvar$ = $ex$.ToString();
$remainingcatchstatements$
}]]></SearchPattern>
<Params />
<Placeholders>
<StatementPlaceholder Name="trystatements" Minimal="-1" Maximal="-1" />
<StatementPlaceholder Name="remainingcatchstatements" Minimal="1" Maximal="-1" />
<IdentifierPlaceholder Name="tmpvar" Type="" ExactType="False" RegEx="" CaseSensitive="True" />
<IdentifierPlaceholder Name="ex" Type="" ExactType="False" RegEx="" CaseSensitive="True" />
</Placeholders>
</Pattern>
It does match, but when I invoke the replace there is no change. The result I expected was this (note the ex.ToString() line is removed):
public bool SetPandGValue( byte[] pValue, byte[] gValue )
{
try
{
ic.CreateDHDestinationServiceProvider( pValue, gValue );
return true;
}
catch( Exception ex )
{
return false;
}
}
Thanks,
Josh
Please sign in to leave a comment.