如何让Visual Studio自动为功能块生成大括号?

Luk*_*uke 11 c# visual-studio

我可以发誓我已经看到人们键入函数头然后按一些键组合来自动创建函数括号并将光标插入它们之间,如下所示:

void foo()_
Run Code Online (Sandbox Code Playgroud)

void foo()
{
    _
}
Run Code Online (Sandbox Code Playgroud)

这是内置功能吗?

Luk*_*uke 6

这些工具看起来很不错(特别是Resharper,但价格在200-350美元!)但我最后只记录了一个宏并将其分配给ctrl + alt + [

Macro出现如下:

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
Run Code Online (Sandbox Code Playgroud)

编辑:我使用宏录制器来制作它并没有太糟糕


pc1*_*ter 5

查看Resharper - 它是一个具有此功能的Visual Studio插件,以及许多其他开发帮助.

另请参阅C#Completer,另一个附加组件.

如果您想自己动手,请查看此文章.然而,疯狂的人应该这样做.