0

我将通过一个我想要的例子来展示:

原始状态:

using (var myobject = new DisposableObject())
{
  //some code that no longer use myobject
  int x = 5;
  int y = x+5;
}

期望的状态:

  //some code that no longer use myobject
  int x = 5;
  int y = x+5;

我想通过键盘组合或 resharper 命令或宏来实现此更改。所以不要通过手动删除大括号和使用行。这可能吗?

4

2 回答 2

0

不是一个命令,但这会起作用(需要 Resharper):

  • 删除“使用”行(shift+ del
  • 将光标放在{并点击alt+ enter,
  • 选择“删除大括号”。
于 2012-09-27T07:55:04.427 回答
0

如果大括号和 using 块位于不同的行中,此宏也可以使用,只需添加一个快捷方式:

Sub deleteusingblock()
    DTE.ExecuteCommand("Edit.LineDelete")
    DTE.ActiveDocument.Selection.EndOfLine()
    Dim sel As TextSelection = DTE.ActiveDocument.Selection
    Dim ap As VirtualPoint = sel.ActivePoint

    If (sel.Text() <> "") Then Exit Sub
    ' reposition
    DTE.ExecuteCommand("Edit.GoToBrace") : DTE.ExecuteCommand("Edit.GoToBrace")

    If (ap.DisplayColumn <= ap.LineLength) Then sel.CharRight(True)

    Dim c As String = sel.Text
    Dim isRight As Boolean = False
    If (c <> "(" And c <> "[" And c <> "{") Then
        sel.CharLeft(True, 1 + IIf(c = "", 0, 1))
        c = sel.Text
        sel.CharRight()
        If (c <> ")" And c <> "]" And c <> "}") Then Exit Sub
        isRight = True
    End If

    Dim line = ap.Line
    Dim pos = ap.DisplayColumn
    DTE.ExecuteCommand("Edit.GoToBrace")
    If (isRight) Then sel.CharRight(True) Else sel.CharLeft(True)

    sel.Text = ""
    If (isRight And line = ap.Line) Then pos = pos - 1
    sel.MoveToDisplayColumn(line, pos)
    sel.CharLeft(True)
    sel.Text = ""
End Sub

(来源:克里斯的回答:在 Visual Studio 中删除匹配的大括号

于 2012-09-27T08:30:26.360 回答