This week, we look at code snippets. This is one of my favorite features in Visual Studio. Whenever I give talks, I always use code snippets. Some people copy code from Notepad. Some people drag code from the Toolbox. Not me. I create snippets. I store all the snippets for each talk in their own folder. Visual Studio maintains a list of folders that contain snippets. The list includes the folders VS installed. It can also include additional folders containing snippets you acquired or created. So before a talk, I will tell VS to use the snippets in the talk's folder. After the talk, I can remove that folder from the list if I want.
For quite some time, I used the VB Snippet Editor written by Bill McCarthy (a VB MVP) (http://billmccarthy.com/Projects/Snippet_Editor/) to create snippets. In spite of its name, it create both VB and C# snippets. Then I discovered the Snippet Designer extension (http://visualstudiogallery.msdn.microsoft.com/B08B0375-139E-41D7-AF9B-FAEE50F68392). Because the VS Toolbox show is all about extensions, that is now my snippet tool of choice. Sorry Bill. 🙂
In this episode of the show, I demonstrate how to use not only snippets that ship with VS, but also how to use the Snippet Designer to create your own snippets.