![](/img/trans.png)
[英]Is it possible to auto complete with function braces? c# visual studio
[英]How do I make Visual Studio auto generate braces for a function block?
我可以發誓我已經看到人們鍵入函數頭然后按一些鍵組合來自動創建函數括號並將光標插入它們之間,如下所示:
void foo()_
至
void foo()
{
_
}
這是內置功能嗎?
這些工具看起來很不錯(特別是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
編輯:我使用宏錄制器來制作它並沒有太糟糕
查看Resharper - 它是一個具有此功能的Visual Studio插件,以及許多其他開發幫助。
另請參閱C#Completer ,另一個附加組件。
如果您想自己動手,請查看此文章 。 然而,瘋狂的人應該這樣做。
看看視覺輔助 。
我剛剛在@ 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.