Visual Studio 编辑器:删除结构化 IF/End If

发布于 2024-07-06 07:35:57 字数 494 浏览 4 评论 0原文

有没有简单的方法来删除 IF/End If 结构化配对。 如果能够通过一次按键完成此操作,那就太好了(我也使用 Refactor! Pro),

现在这就是我所做的:

  1. 删除 IF 行,
  2. 观看 Visual Studio 重新格式化代码以正确排列,同时考虑到缺少 IF 的帐户。
  3. 导航到 End If
  4. 删除 End If

,即在下面的示例中,我想将代码从

IF Value = True Then
  DoSomething()
  DoSomething2()
End IF

To更改为

DoSomething()
DoSomething2()

Is there and easy way to remove the IF/End If structured pairing.
Being able to do this in one keystroke would be nice (I also use Refactor! Pro)

Right now this is what I do:

  1. Delete the IF line
  2. Watch Visual Studio reformat the code to line up correctly taking into account that the IF is Missing.
  3. Navigate to the End If
  4. Delete the End If line

i.e. In the following example I want to change the code from

IF Value = True Then
  DoSomething()
  DoSomething2()
End IF

To

DoSomething()
DoSomething2()

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

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

发布评论

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

评论(1

旧人 2024-07-13 07:35:57

虽然这不是 Martin Fowler 的书 重构 所指定意义上的字面重构,但这就是我使用 resharper 来实现此目标:

  1. 移动/单击类似于 if 语句
  2. control + delete 删除该行
  3. Alt + Enter,并且选项删除大括号将是第一个指定的选项。
  4. 输入

完成。 不太简单,但击键很短,也不太复杂,而且我不必花费/浪费时间使用愚蠢的箭头键或鼠标来完成此类代码更改。

我相信,Resharper 从 4.0 开始支持 VB.net 代码。

While this is not a literal refactoring in the sense specified by Martin Fowler's book Refactoring, This is how I use resharper to achieve this goal:

  1. Move/click on like with if statement
  2. Press control + delete to delete the line
  3. Press Alt + enter, and the option remove braces will be the first one specified.
  4. Press enter

Done. Not quite simple, but the keystrokes are short, and not too complicated, and I don't have to spend/waste time with dumb arrow keys or the mouse to accomplish this type of code change.

Resharper supports VB.net code as of 4.0, I believe.

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