Stop VS 2010 from Auto Creating Braces After else keyword

橙三吉。 提交于 2019-12-22 05:21:11

问题


I'm using VS 2010, and I'm getting constantly annoyed when I type "else" and then it auto returns line and adds braces. Something like:

else
{

}

I cannot imagine I'm the only one who often puts one-liners after the else and prefers no braces. How do I stop this from happening?


回答1:


I also found this behavior very annoying.

My first attempt involved opening the Templates Explorer (ReSharper / Templates Explorer...), selecting C#, then unchecking "else". This did get rid of the braces. Unfortunately, hitting enter after "else" now just added a space! I was having to hit enter twice. Not quite what I was hoping for.

But if you double-click on the else template it opens up an editor where you can specify what happens. I found that simply removing the braces gave me the functionality I desired - hitting enter after an else was now putting me on a new line, tabbed over under the else - without braces.

To recap, to fix this you need to open Resharper's Templates Explorer, select the C# scope, then double-click on the else template and remove the braces. Your template "snippet" should look like this (just two lines):

else
  $END$

This works in Resharper 6.1 and Visual Studio 2008. I have no idea about other versions of the software.




回答2:


Okay, finally figured out what the hell is doing this. I have ReSharper installed on this machine, and apparently the "else" keyword is a ReSharper autocomplete keyword. So even after I turned off the braces completion, ReSharper was still kicking in and adding them. Rage. In order to stop this, you have to turn off the ReSharper autocomplete.




回答3:


I don't think there's any way to disable brace auto-complete for specific keywords. If you go to:

Tools -> Options -> Text Editor -> C# -> Formatting

you'll find the various formatting options. It's possible to disable auto complete in general or affect indentation and such, but I don't see any way to disable brace auto complete for specific keywords.




回答4:


Are you using Productivity Power Tools? You can turn it off in Tools, Options, "Productivity Power Tools", "Automatic Brace Completion". (I know I do)



来源:https://stackoverflow.com/questions/6664884/stop-vs-2010-from-auto-creating-braces-after-else-keyword

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!