有什么办法可以在 VS2008 中用花括号 {} 包围代码块? [英] Any way to surround code block with Curly Braces {} in VS2008?

查看:31
本文介绍了有什么办法可以在 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).

我们有一个编码标准,在ifelse 之后的ifelse 之后包括甚至一行代码,所以如果我可以只需让 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 Studio VersionCode SnippetsVisual C#My Code Snippets"

使用:

选择文本块.
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天全站免登陆