c# - 使用模式方法调用的 Resharper 搜索

标签 c# replace resharper

我想用“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;
}

替换为:

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

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

我试过

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

这不起作用,因为在任何需要替换的代码中都找不到方法调用。

如何做到这一点?

最佳答案

您需要确保使用正确的 placeholder type当您设置搜索时。

这里,result 应该是一个标识符占位符usp_IsDbObjectsOK 应该是一个表达式占位符。当我这样做时,替换会如您预期的那样工作。

关于c# - 使用模式方法调用的 Resharper 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29970808/

相关文章:

c# - 如何获取MEF中的所有方法

c# - 如何根据条件从数据库中分离数据?

replace - 如何在 openrefine GREL 中替换动态正则表达式?

c# - 试用 StyleCop 后恢复 Resharper - 获取/设置换行符

Resharper 5 XML 注释格式

c# - 源文件 X 在 c# 中的 Windows 系统文件保护下?

c# - 基于数组对列表进行排序

mysql - 我想用一个查询替换从 "300-21-2"到 "300-21-02"的一列中的文本

用于搜索并替换为 "match words only"选项的 Python 脚本

visual-studio - 我可以添加一个命令以使 ReSharper 重复上次测试运行到 Visual Studio 中的右键单击上下文菜单吗?