Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make Visual Studio place curly braces on the same line as an if statement (in HTML)?

In Visual Studio while designing MVC views (in .aspx or .ascx files), I often use if statements. When I auto-format (Ctrl+K+D), Visual Studio wraps the braces in this really ugly and hard to read way:

<% if (Model.UserIsAuthenticated)     { %>        (some HTML goes here...) <% } %> 

Is there any way to make Visual Studio auto-format like this instead:

<% if (Model.UserIsAuthenticated) { %>        (some HTML goes here...) <% } %> 

Or is there a better way to do this? I don't want to use Razor quite yet, but it looks like it would solve my problem. I'm using VS2010 with Resharper 5, if that helps.

like image 273
Mike Comstock Avatar asked Oct 26 '10 01:10

Mike Comstock


People also ask

How do you match curly braces in Visual Studio?

I found this for you: Jump between braces in Visual Studio: Put your cursor before or after the brace (your choice) and then press CTRL + ] . It works with parentheses ( ), brackets [ ] and braces { }. From now on you don't need to play Where's Waldo? to find that brace.

Do you need curly braces for if statements?

If the true or false clause of an if statement has only one statement, you do not need to use braces (also called "curly brackets"). This braceless style is dangerous, and most style guides recommend always using them.


1 Answers

Under ToolsOptionsText EditorC#FormattingNew Lines are the rules for the open brace on each case (new methods, control blocks, etc), maybe you can find the one you want there.

enter image description here

like image 167
Felix Martinez Avatar answered Sep 20 '22 21:09

Felix Martinez