Resharper Find With Pattern - 帮助在多个类中查找构造函数

发布于 2025-01-03 09:09:05 字数 1107 浏览 3 评论 0原文

目标:

在特定项目的所有类中,找到如下所示的所有构造函数:

public Alert(DBConnection dbConnection, SqlInt32 Alert_ID)
    : base (dbConnection, Alert_ID)
{
}

并替换为:

public Alert(DBConnection dbConnection, SqlInt32 Alert_ID)
    : base (dbConnection, Alert_ID)
{
}

protected Alert() {}

protected override Generated.Alert GetNew()
{
    return new Alert();
}

我已经尝试了 Resharper 的 Find with Pattern 选项中我能想到的所有模式,但即使是最简单的表达式,例如: public Alert(DBConnection dbConnection, SqlInt32 Alert_ID) 产生“没有找到”。

Resharper 无法识别方法/构造函数吗?它只能在其中找到代码吗?


好的 - 更新 - 这个模式找到了我想要的匹配:

public $t$(DBConnection dbConnection) : base(dbConnection)
{
$stmt$
}

所以下一个目标是插入新方法 - 就像一个新的公共空构造函数。

尝试这个替换模式 - 但同样,没有乐趣:

public $t$(DBConnection dbConnection) : base(dbConnection)
{
$stmt$
}

public $t$() {}

如果我尝试类似

public $t$(DBConnection dbConnection) : base(dbConnection) { $stmt$ //你好 它

有效 - 注释被插入。但如果我在声明的搜索模式之外添加代码,就没有这样的运气了......

那么现在怎么办?

Goal:

In all classes in a particular project, find all constructors which look like this:

public Alert(DBConnection dbConnection, SqlInt32 Alert_ID)
    : base (dbConnection, Alert_ID)
{
}

and replace with this:

public Alert(DBConnection dbConnection, SqlInt32 Alert_ID)
    : base (dbConnection, Alert_ID)
{
}

protected Alert() {}

protected override Generated.Alert GetNew()
{
    return new Alert();
}

I've tried every pattern I can think of in Resharper's Find with Pattern option, but even the simplest expression like: public Alert(DBConnection dbConnection, SqlInt32 Alert_ID) yields "Nothing found".

Is Resharper incapable of identifying methods/constructors? Can it only find code within them?


Ok - update - this pattern found the matches I want:

public $t$(DBConnection dbConnection) : base(dbConnection)
{
$stmt$
}

So next goal is to insert new methods - like a new public empty constructor.

Trying this replace pattern - but again, no joy:

public $t$(DBConnection dbConnection) : base(dbConnection)
{
$stmt$
}

public $t$() {}

if I try something like

public $t$(DBConnection dbConnection) : base(dbConnection)
{
$stmt$
//hi
}

it works- the comment is inserted. But if I add code outside of the declared search pattern, no such luck...

So now what?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

匿名。 2025-01-10 09:09:05

以下内容对我有用:

public WCFTest1Tests()
{
$code$
}

其中 $code$ 设置为任意数量的语句。

The following just worked for me:

public WCFTest1Tests()
{
$code$
}

Where $code$ is set to any number of statements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文