Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resharper Search with pattern method call

I want to replace this part of code using "Search with pattern...":

public bool IsDbObjectsOK()
{
    var result = 0;
    result = usp_IsDbObjectsOK();
    if (result == 0)
        return true;
    return false;
}

public bool UnlockWindow()
{
    var result = 0;
    result = usp_UnlockWindow();
    if (result == 0)
        return true;
    return false;
}

Replace with:

public bool IsDbObjectsOK()
{
    return usp_IsDbObjectsOK() == 0;
}

public bool UnlockWindow()
{
    return usp_UnlockWindow() == 0;
}

I tried to use

var $result$ = 0;
$result$ = $usp_IsDbObjectsOK$();
if ($result$ == 0)
    return true;
return false;

This doesn't work, because the method call isn't found in any of the code that needs to be replaced.

How to do this?

like image 208
Wouter D Avatar asked Sep 29 '22 02:09

Wouter D


1 Answers

You need to make sure that you use the correct placeholder type when you set up the search.

Here, result should be an Identifier Placeholder and usp_IsDbObjectsOK should be an Expression Placeholder. When I do that, the replace works as you'd expect.

like image 172
Patrick Quirk Avatar answered Nov 13 '22 04:11

Patrick Quirk