How to: Creating Code Snippets for Visual Studio 2005/2008
Code Snippets was one of my favorite "new features" in Visual Studio 2005 and has continued to be in Visual Studio 2008. If you've never used them, what they are (simple explanation) is a macro-capability built into the Visual Studio IDE. They allow you to type single/multiple key strokes to define blocks of code. So imagine: If I want to open a database connection, adapter, create a dataset, and fill it. I could type the 5+ lines of code each time I have to do this (which is often) or I could just type something like "DataSetCode" and hit the enter button, and all of the code that I would normally hand write each time, would show up in the IDE (like a Macro). It even has the ability to prompt me for pieces like the dataset name, connection string pieces, etc., that might vary each time I write my code.
Great feature! There are some already built in to Visual Studio, others that you can download.
If you want to learn how to build your own, check these links out (taken from this MSDN article)
- How to: Create a Basic Code Snippet (Describes how to create a simple code snippet.)
- How to: Create a New Snippet with Imports and References (Explains how to add Imports and References elements to Visual Basic code snippets.)
- How to: Create a New Snippet with Replacements (Explains how to add customizable literals and objects to code snippets.)
- How to: Create Code Snippets for XML Files (Explains how to create a code snippet for XML files.)
BTW, if you don't like hand writing XML, then you might want to download this free Code Snippet Editor called: "Snippy": Click here to access the download
~ Robert Shelton
Technorati Tags: Visual Studio