C# 如何使Visual Studio为功能块自动生成大括号?
我可以发誓,我见过有人键入函数头,然后按一些组合键来自动创建函数大括号,并在它们之间插入光标,如下所示:C# 如何使Visual Studio为功能块自动生成大括号?,c#,visual-studio,C#,Visual Studio,我可以发誓,我见过有人键入函数头,然后按一些组合键来自动创建函数大括号,并在它们之间插入光标,如下所示: void foo()_ 到 这是一个内置功能吗?它可以通过使用代码片段来实现,有些代码片段已经内置(尝试键入“svm”并点击TAB-TAB) 网上有大量关于创建这些的信息: 有一个谷歌!我经常用它们D也来看看。检查-它是一个Visual Studio附加组件,具有此功能,以及许多其他开发帮助 另请参见,另一个附加组件 如果你想推出你自己的,看看吧。不过,这样做真是太疯狂了。这些工具看起来
void foo()_
到
这是一个内置功能吗?它可以通过使用代码片段来实现,有些代码片段已经内置(尝试键入“svm”并点击TAB-TAB) 网上有大量关于创建这些的信息: 有一个谷歌!我经常用它们D也来看看。检查-它是一个Visual Studio附加组件,具有此功能,以及许多其他开发帮助 另请参见,另一个附加组件 如果你想推出你自己的,看看吧。不过,这样做真是太疯狂了。这些工具看起来不错(尤其是Resharper,但售价200-350美元!)但我最终只是录制了一个宏并将其指定给ctrl+alt+[ 宏结果如下:
Sub FunctionBraces()
DTE.ActiveDocument.Selection.NewLine
DTE.ActiveDocument.Selection.Text = "{}"
DTE.ActiveDocument.Selection.CharLeft
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.LineUp
DTE.ActiveDocument.Selection.Indent
End Sub
编辑:我用宏录制器制作了这个,还不错我刚刚根据上面的@Luke创建了一个。这个,你想按Enter键,然后按组合键,它将插入:
if ()
{
}
else
{
}
它会通过if语句将光标放在括号中
Sub IfStatement()
DTE.ActiveDocument.Selection.Text = "if ()"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "else"
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.LineUp(False, 7)
DTE.ActiveDocument.Selection.EndOfLine()
DTE.ActiveDocument.Selection.CharLeft(3)
End Sub
Sub IfStatement()
DTE.ActiveDocument.Selection.Text = "if ()"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "else"
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.LineUp(False, 7)
DTE.ActiveDocument.Selection.EndOfLine()
DTE.ActiveDocument.Selection.CharLeft(3)
End Sub