Resharper Find With Pattern - 帮助在多个类中查找构造函数
目标:
在特定项目的所有类中,找到如下所示的所有构造函数:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下内容对我有用:
其中 $code$ 设置为任意数量的语句。
The following just worked for me:
Where $code$ is set to any number of statements.