Surround code block with curly braces?

You do not need Resharper for this. You can use the “surround with” with a custom snippet.

Then you can select your text with Ctrl + K, Ctrl + S and select the snippet {} in the custom snippet. In order to create such a snippet :

  1. Create a “.snippet” file containing the content below
  2. Go to the snippet manager (Tools > Code Snippets Manager)
  3. Click import and select the file you just created

Use the following snippet :

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

Leave a Comment