Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resharper find pattern and replace - how to insert strings

We have a sanity check method

void IsNotNull<T>(T obj){...}

invocation

IsNotNull(obj); 

I want to replace this to invoke the other overload that takes a second param of type string (message)

void IsNotNull<T>(T obj, string message){...}

So I want to change the invocation as

IsNotNull(obj, "obj is null");

I'm trying to achieve this using resharper's find pattern and replace.

So my find pattern is : IsNotNull($args$) - This works fine and it finds the method calls

Replace pattern: IsNotNull($args$, "$args$ is null") - This doesn't do anything

I also tried this IsNotNull($args$, """" + $args$ + """")

--Edited-- The suggestion box showing the correct wording(for both argument and identifier), but once applied it's different. I'm using Resharper 6

enter image description here

After applying the suggestion I get this enter image description here

When I click Edit Pattern enter image description here

like image 282
Nasmi Sabeer Avatar asked Dec 31 '12 13:12

Nasmi Sabeer


1 Answers

What is your $args$ parameter defined as in the Search and Replace? If you make it to be Identifier, then you replace should work:

Find: IsNotNull($args$) - where $args$ is an Identifier
Replace: IsNotNull($args$, "$args$ is null")

You should have the result you want, i.e. IsNotNull(obj, "obj is null").

like image 136
Igal Tabachnik Avatar answered Oct 06 '22 01:10

Igal Tabachnik