我可以让 Visual Studio 将花括号与 if 语句(在 HTML 中)放在同一行吗? [英] Can I make Visual Studio place curly braces on the same line as an if statement (in HTML)?

查看:28
本文介绍了我可以让 Visual Studio 将花括号与 if 语句(在 HTML 中)放在同一行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Studio 中设计 MVC 视图(在 .aspx.ascx 文件中)时,我经常使用 if 语句.当我自动格式化 (Ctrl+K+D) 时,Visual Studio 以这种非常丑陋且难以阅读的方式包装大括号:

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...)
<% } %>

有没有办法让 Visual Studio 像这样自动格式化:

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

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

或者有更好的方法来做到这一点?我还不想使用 Razor,但看起来它可以解决我的问题.如果有帮助,我将 VS2010 与 Resharper 5 一起使用.

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.

推荐答案

Under ToolsOptionsText EditorC#FormattingNew Lines 是每种情况(新方法,控制块等)的左大括号的规则,也许你可以找到你想去那里.

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.

这篇关于我可以让 Visual Studio 将花括号与 if 语句(在 HTML 中)放在同一行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆