使用 Resharpers 模式目录查找具有 3 个以上参数的构造函数
是否可以在 Resharper 的模式目录中创建搜索模式来查找所有具有 3 个以上参数的构造函数?
如果是这样,怎么办?
我的问题是我不知道如何告诉 Resharper 只有构造函数定义应该匹配。
Is it possible to create a search pattern in the pattern catalog of Resharper to find all constructors with more than 3 parameters?
If so, how?
My problem is that I don't know how to tell Resharper that only constructor definitions should match.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,Resharper 中的模式只能在方法内进行匹配。所以你无法匹配构造函数声明。
我只是尝试了以下模式:
其中 type 是类型的占位符(谁会猜到?),args 至少有 3 个参数。
这确实找到了至少 3 个参数构造函数的所有使用,但它不会找到未使用的构造函数,最重要的是,它会找到这个:
所以也许如果你认为你会遇到这些情况,您应该尝试使用正则表达式查找,而不是使用 Resharper 模式。这可能很难,因为想想 C# 语法相当复杂,但你可以得到一些东西......
编辑:我改编了 Visual Studio 正则表达式搜索构造函数声明,识别新行和至少参数(可以有可选值):
它很难看,主要是因为 VS 自定义正则表达式没有对标准 \w、{2,} 和 ? 进行任何翻译>。
As far as I know the patterns in Resharper can only be matched within a method. So you couldn't match the constructor declaration.
I just tried the following pattern though:
Where type is a placeholder for a type (who would have guessed?) and args for at least 3 arguments.
This indeed finds all uses of at least 3 arguments constructors, but it wouldn't find constructors that are not used, and most importantly, it would find this:
So maybe if you think you're going to have these cases, instead of using Resharper patterns you should try to use regex Find. It can be hard because come to think of it C# syntax is quite complex, but you could get to something...
Edit: I adapted a visual studio regex search for a constructor declaration, recognizes new lines and at least arguments (which can have optional values):
it's ugly mainly because the VS custom regex doesn't have any translation for the standard \w, {2,} and ?.
我知道这个问题是专门针对 R#6.0 的,但我想为 R# 2016.3 提供答案,因为我最近也有同样的问题。
Resharper 2016(.3.1)
Search with Pattern 允许这种类型的搜索。您需要执行以下操作:
选择“Resharper”>“查找>使用模式搜索
添加三个占位符:
确保将搜索模式设置为
C#
将模式设置为以下内容:
设置
查找范围
根据需要(例如 解决方案)。然后点击查找。您最终应该得到一个如下所示的搜索框:
这将找到包含您感兴趣的参数数量的所有(公共)构造函数。我能够在多个解决方案中成功使用它。作为一个额外的好处,似乎很高兴找到多行(而不仅仅是单行)带有参数列表的构造函数。
I know this question is specifically targetted at R#6.0, but I wanted to provide an answer for R# 2016.3, as I had the same question recently.
Resharper 2016(.3.1)
Search with Pattern allows this type of searching. Here's what you need to do:
Select Resharper > Find > Search With Pattern
Add Three Placeholders:
Ensure that you set the Search Pattern to
C#
Set the pattern to the following:
Set
Look In
as you need to (e.g. Solution). And hit Find.You should end up with a search box that looks like this:
This will find all (public) constructors which contain the number of params you are interested in. I was able to use this within several solutions successfully. As an added bonus, it seems to be quite happy to find constructors with param lists over multiple lines, not just a single line.