简体   繁体   English

我如何使用 resharper 找到所有空捕获?

[英]How can i find all empty catch with resharper?

I know that there is the possibility to use search pattern but I don't know how to implement this feature我知道可以使用搜索模式,但我不知道如何实现此功能

You can mark any code in Visual Studio and then click, for example the empty try-catch, then go您可以在 Visual Studio 中标记任何代码,然后单击,例如空的 try-catch,然后单击 go

  • Extensions -> Resharper -> Find -> Search with pattern扩展 -> Resharper -> 查找 -> 使用模式搜索

Now resharper created a pattern for you matching that code:现在 resharper 为您创建了一个匹配该代码的模式:

try
{
$statement$
}
catch ($Exception$ $e$)
{
}

整形器找到模式

You can edit it or add new placeholders and save it, then click Find.您可以编辑它或添加新的占位符并保存它,然后单击“查找”。

In this case it might be a good idea to add another pattern that matches also empty catch blocks that have no Exception parameter:在这种情况下,添加另一个匹配没有Exception参数的空 catch 块的模式可能是个好主意:

try
{
$statement$
}
catch
{
}

By the way, this matches also if the catch contains comments like顺便说一下,如果 catch 包含类似的评论,这也会匹配

// don't do anything

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#:找到所有空的catch块 - C#: Find all empty catch blocks 如何使用ReSharper创建NUnit测试? - How can I create NUnit tests with ReSharper? ReSharper或VS-如何在所有子类中自动生成新抽象成员的默认实现? - ReSharper or VS - how can I auto generate a default implementation of a new abstract member in all sub-classes? 如何使 ReSharper 不将所有 my.Bind 语句添加到一行? - How can I make ReSharper not add all my .Bind statements to the one line? Resharper 4.5:如何丢弃接口并更改对唯一实现的所有引用? - Resharper 4.5: How can I discard an interface and change all references to the only implementation? 我可以用 throw 去掉空的 catch 吗? - Can I remove empty catch with throw? 我可以使用正则表达式在Resharper的自定义模式中查找字符串吗? - Can I use regex to find strings in Resharper's Custom Patterns? 如何禁用单个ReSharper“参数可以为类型”建议? - How can I disable a single ReSharper “Parameter Can Be of Type” suggestion? .Net core 3.1 如何捕获所有错误并在辅助类中找到异常位置 - .Net core 3.1 how can catch all errors and find the exception place in the helper classes 是否有ReSharper快捷方式来查找某种类型的所有实例化? - Is there a ReSharper shortcut to find all instantiations of a certain type?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM