Using Code Snippets in Visual Studio 2005, Page 3
After you have created the .snippet file and copied it to the My Code Snippets folder, you can use the snippet to generate code. To insert the snippet, select Edit|Intellisense|Insert Snippet, navigate through the list of snippets—which are organized just as they are in the file system—and select the snippet (see Figure 2).
Figure 2: Ctrl K+Ctrl X Display the List of Snippets
After inserting the snippet, code elements that were marked as replaceable will be highlighted (see Figure 3). Replace the highlighted elements with the actual value. For example, if you want the Customer collection in Figure 3, you can leave the code as is. Otherwise, replace all of the highlighted instances of Customer with the type you will be collecting.
Figure 3: Replaceable Elements Are Highlighted
Snippets Have Come a Long Way
When you follow the examples in this article, keep in mind that VS 2005 is still in beta. Using beta software can be frustrating, but it can also be a lot of fun. Be patient.
In any case, I hope you got a sense of how far code snippets have evolved from simply copying and pasting text in the toolbox. They now offer manageable, shareable code with replaceable elements, assembly references, and imports statements. I'd say that makes for more than a simple a drag-and-drop article.
About the Author
Paul Kimmel is the VB Today columnist for www.codeguru.com and has written several books on object-oriented programming and .NET. Check out his upcoming book UML DeMystified from McGraw-Hill/Osborne (Spring 2005) and Expert One-on-One Visual Studio 2005 from Wrox (Fall 2005). Paul is also the founder and chief architect for Software Conceptions, Inc, founded 1990. He is available to help design and build software worldwide. You may contact him for consulting opportunities or technology questions at firstname.lastname@example.org.
If you are interested in joining, sponsoring a meeting, or posting a job, check out www.glugnet.org, the Web page of the Greater Lansing area Users Group for .NET.
Copyright © 2005 by Paul T. Kimmel. All Rights Reserved.
Page 3 of 3