您如何获得服务器块<%%>在Visual Studio中很好地格式化? [英] How do you get server blocks <% %> to format well in Visual Studio?

查看:87
本文介绍了您如何获得服务器块<%%>在Visual Studio中很好地格式化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我经常使用ASP.NET MVC,这意味着使用服务器会阻塞一大堆.当我键入内容时,Visual Studio会执行以下奇怪操作:

I'm using ASP.NET MVC a lot recently which means using server blocks a bunch. Visual Studio does this strange thing when I type:

<% } %>

然后按Enter,我得到了:

and hit enter, I get this:

<%
     }
     %>

这是我所见过的最难看的东西,通常是最恐怖的东西.我已经非常自定义了Ctrl + K + D行为,执行此操作后,除一种情况外,其他所有内容都按照我想要的方式显示.有人对如何自定义此有任何建议吗?

Which is unsightly and generally the most horrible thing I've ever seen. I've customized the Ctrl+K+D behavior pretty heavily and when I do this I get everything to look the way I want except for this one case. Anyone have any suggestions on how to customize this?

推荐答案

查看行为.我不知道您可以为HTML编辑器覆盖它.它展现了C#编辑器首选项中定义的确切行为.

Looking at the behavior. I don't know that you can override it just for the HTML editor. It is exhibiting the exact behavior that is defined in the C# editor preferences.

我想您可以在C#编辑器首选项中修改右括号的行为,但这将对您的.cs文件造成麻烦.

I suppose you could modify the behavior for a closing brace in the C# editor preferences, but it would do fugly things to your .cs files.

我厌倦了尝试寻找其他方法来做到这一点.所以我写了这个宏.在VS 2k8中测试.不是2k5.您可以看到它的作用.另外,对VB感到抱歉,但这是宏编辑器的默认设置.

I got tired of trying to find other ways to do it. So I wrote this macro. Tested in VS 2k8. Not 2k5. You can see what it does. Also, sorry about the VB, but it was the default for the macro editor.

Sub FixFormatCurrentFile()

    Dim selection As TextSelection = DTE.ActiveDocument.Selection
    Dim fixed As String = "<% } %>"
    Dim regex As String = "\<\%:Wh*\}:Wh*\%\>"

    While selection.FindPattern(regex, vsFindOptions.vsFindOptionsRegularExpression)
        selection.ReplacePattern(regex, fixed, vsFindOptions.vsFindOptionsRegularExpression)
    End While
End Sub

这篇关于您如何获得服务器块&lt;%%&gt;在Visual Studio中很好地格式化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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