Friday 11 July 2008

.Net Surround With Snippet File

How to create a .Net Surround With Snippet.

1.

On the File menu, click New and then click File.
2.

Click XML File and then click Open.
3.

On the File menu, click Save .
4.

In the Save as type box, select All Files (*.*).
5.

In the File name box, enter a file name with the .snippet file name extension.
6.

Click Save.

Code Example....


<?xml version="1.0" encoding="utf-8" ?>

<CodeSnippet Format="1.0.0">

<Header>

<Title>TestJo</Title>

<Shortcut>TestJo</Shortcut>

<Description>Expansion snippet for TestJo</Description>

<SnippetTypes>

<SnippetType>Expansion</SnippetType>

<SnippetType>SurroundsWith</SnippetType>

</SnippetTypes>

</Header>

<Snippet>


<Code Language="csharp" Format="CData">

<![CDATA[

try

{

$selected$$end$

}

catch

{

throw(ex);

}

]]>

</Code>

</Snippet>

</CodeSnippet>




I think the best thing to do is add the folders into code manager rather than using the imports button. This means that you will always access the updated version of the snippets.

Open Tools >> Code Snippets Manager
Press Add.
Browse to the first folder above.
Repeat for second folder.
Access by:
Right click and select insert snippet or surrounds with.
Type the name of the snippet and intellisense will pick it up, and then press tab.

1 comment:

Chris said...

Think these are great. There a few sites on the web that give you free access to snippets. Would you recommend any?

Free Hit Counter