Visual Studio Tip – Create your own code snippets

Here we’re going to show how easy it is to extend Visual Studio by adding a new snippet that is both an "Expansion" and "SurroundWith" type.  This snippet will put in a System.Diagnostics.Trace statement for us.

First we create the following XML.  Note the "SnippetTypes", the "ToolTip", and the "Code" elements.  We save this file to the Visual Studio Snippets folder which in the case of this particular box with VS05 is "C:\Program Files (x86)\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#". 

 

Now if we go into the IDE and type trace then hit tab tab in quick succession to execute the expansion snippet we get the following code snippet,

To use the SurroundWith snippet type press ctrl+k then ctrl+s in quick succession.  By highlighting the string variable myString we get the following code snippet,

Advertisements
This entry was posted in .NET. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s