任何方式环绕用花括号{}在VS2008的代码块? [英] Any way to surround code block with Curly Braces {} in VS2008?

查看:344
本文介绍了任何方式环绕用花括号{}在VS2008的代码块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是觉得自己需要封闭的代码在大括号块 {} ,但不幸的是不包括在C#环绕代码段,这似乎是一个疏忽。我找不到上建立自己的环绕声片段或者(只是其他类型的片段的)东西。

I always find myself needing to enclose a block of code in curly braces { }, but unfortunately that isn't included in the C# surround code snippets, which seems to be an oversight. I couldn't find anything on building your own surround snippets either (just other kinds of snippets).

我实际运行ReSharper的太多,但它似乎不具备此功能是(或者我还没有想出如何激活它)。

I am actually running Resharper too, but it doesn't seem to have this functionality either (or I haven't figured how to activate it).

我们必须包括一个编码标准的之后如果其他代码的连一行在大括号,所以如果我可以只让ReSharper的做自动的重构会更加美好!

We have a coding standard of including even a single line of code after an if or else in curly braces, so if I could just make Resharper do that refactoring automatically that would be even better!

推荐答案

这里是一个快速和肮脏的片段来做到这一点。

Here is a quick and dirty snippet to do just that.

要安装:

保存代码 SurroundWithBraces.snippet <我的文档> \Visual工作室Version\Code Snippets\Visual C#\My代码段

要使用:

文本结果
按选择块。 按Ctrl + K,Ctrl + S键结果
选择了我的代码段,括号

Select block of text.
Press Ctrl+K, Ctrl+S
Chose My Code Snippets, braces

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>braces</Title>
      <Shortcut>braces</Shortcut>
      <Description>Code snippet to surround a block of code with braces</Description>
      <Author>Igor Zevaka</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="csharp">
        <![CDATA[{
        $selected$ $end$
     }]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

这篇关于任何方式环绕用花括号{}在VS2008的代码块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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