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

假如想象 提交于 2019-12-20 09:14:00

问题


In Visual Studio while designing MVC views (in .aspx or .ascx files) I often use if statements. When I auto-format (Ctrl-K,D), VS 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.


回答1:


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.




回答2:


the formatting is handled by individual plugins, for js you can use the following setting:

// Defines whether an open brace is put onto a new line for functions or not.
"javascript.format.placeOpenBraceOnNewLineForFunctions": true,


来源:https://stackoverflow.com/questions/4020070/can-i-make-visual-studio-place-curly-braces-on-the-same-line-as-an-if-statement

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