<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Visual Studio Hacks &#187; Code Snippets</title>
	<atom:link href="http://visualstudiohacks.com/category/code-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://visualstudiohacks.com</link>
	<description></description>
	<lastBuildDate>Mon, 23 Nov 2009 23:09:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Snippy</title>
		<link>http://visualstudiohacks.com/code-snippets/snippy/</link>
		<comments>http://visualstudiohacks.com/code-snippets/snippy/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 21:07:00 +0000</pubDate>
		<dc:creator>javery</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://vsh.infozerk.net/?p=24</guid>
		<description><![CDATA[
Code Snippets are a handy way to reuse pieces of code to avoid repeating repetitious work repeatedly.&#160; Visual Studio 2003 and 2005 both enable developers to drag snippets of code onto the General Toolbox, but [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>
<p>Code Snippets are a handy way to reuse pieces of code to avoid repeating repetitious work repeatedly.&nbsp; Visual Studio 2003 and 2005 both enable developers to drag snippets of code onto the General Toolbox, but stuffing snippets on the Toolbox isn&rsquo;t very organized and doesn&rsquo;t allow any form of keyboard access.&nbsp; Readers of my <a href="http://visualstudiohacks.com/navtricks"><cite>Confessions of a Keyboard Junkie</cite></a>&nbsp;article may have a feel for how much that would irritate me&hellip;</p>
<p>Visual Studio 2005 includes Intellisense support for adding in code snippets, making it much easier to work with snippets while developing your code.&nbsp; What&rsquo;s cool is that the implementation enables you write your own snippets and drop them into Visual Studio 2005.&nbsp; Microsoft even established <a href="http://msdn2.microsoft.com/en-us/library/ms171418.aspx">an XML schema</a> detailing the layout of snippets.&nbsp; What&rsquo;s not cool is that you&rsquo;ll have to write your snippets inside a CDATA block inside lots of various XML elements.&nbsp; That gets rather odious rather quickly.&nbsp; The following is the destructor snippet included with Visual Studio 2005:</p>
<p><font face="Courier New">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;<br />
&lt;CodeSnippets&nbsp; xmlns=&quot;</font><a href="http://schemas.microsoft.com/visualstudio/2005/codesnippet"><font face="courier new">http://schemas.microsoft.com/<br />
VisualStudio/2005/CodeSnippet</font></a><font face="courier new">&quot;&gt;<br />
&nbsp;&lt;CodeSnippet Format=&quot;1.0.0&quot;&gt;</p>
<p>&nbsp;&nbsp;&lt;Header&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;Title&gt;~&lt;/Title&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;Shortcut&gt;~&lt;/Shortcut&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;Description&gt;Code snippet for destructor&lt;/Description&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;Author&gt;Microsoft Corporation&lt;/Author&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&lt;SnippetTypes&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;SnippetType&gt;Expansion&lt;/SnippetType&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;/SnippetTypes&gt;<br />
&nbsp;&nbsp;&lt;/Header&gt;<br />
&nbsp;&nbsp;&lt;Snippet&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;Declarations&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;Literal Editable=&quot;false&quot;&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ID&gt;classname&lt;/ID&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ToolTip&gt;Class name&lt;/ToolTip&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Default&gt;ClassNamePlaceholder&lt;/Default&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Function&gt;ClassName()&lt;/Function&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Literal&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&lt;/Declarations&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;Code Language=&quot;csharp&quot;&gt;&lt;![CDATA[~$classname$()<br />
&nbsp;{<br />
&nbsp;&nbsp;$end$<br />
&nbsp;}]]&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;/Code&gt;<br />
&nbsp;&nbsp;&lt;/Snippet&gt;<br />
&nbsp;&lt;/CodeSnippet&gt;</p>
<p>&lt;/CodeSnippets&gt;</font></p>
<p>Writing raw XML isn&rsquo;t one of my favorite things, so I&rsquo;m happy when a tool can put the right bits into the right elements for me.&nbsp; The Snippy Power Tool does just that, plus it helps you get the snippets registered and in the appropriate directory for Visual Studio to use them.&nbsp;Instead of writing the XML above, you use Snippy&rsquo;s handy GUI and just fill in fields.</p>
<p><img border="0" src="/files/media/image/snippy1.gif" alt="Snippy's main screen" /></p>
<p>The overview graphic is a bit hard to decypher at its small size, so let&rsquo;s take a zoomed-in look at the major fields</p>
<p><img border="1" src="/files/media/image/snippy2.gif" alt="Snippy Header fields" /></p>
<p>These fields all correspond to <font face="Courier New">&lt;Header&gt;</font>&nbsp;elements in the XML shown above.&nbsp; Writing the actual snippet is much simpler as well.&nbsp; Simply write your code in the field, adding markers for literals or objects as desired.&nbsp;</p>
<p><img border="1" src="/files/media/image/snippy3.gif" alt="Snippet text and literal/object fields" /></p>
<p>Adding and editing literals or objects (text that&rsquo;s replaced in the snippet) is accomplished via a simple dialog box:</p>
<p><img border="0" src="/files/media/image/snippy4.gif" alt="Editing an existing Literal" /></p>
<p>You&rsquo;ll need to save snippets in a location where Visual Studio 2005 can find them.&nbsp; Snippets are stored in either a user&rsquo;s profile folder or in Visual Studio&rsquo;s snippets folder.&nbsp; You can find these paths by pulling open the Code Snippet Manager dialog from Visual Studio&rsquo;s Tools menu and looking at the Location field.</p>
<p>Overall, Snippy is a very handy tool for creating and maintaining snippets.&nbsp; It&rsquo;s not integrated into the Visual Studio environment like <a href="http://www.codekeep.net/">Dave Donaldson&rsquo;s CodeKeep</a> &mdash; but CodeKeep hasn&rsquo;t yet been updated for Visual Studio 2005. (Editors Note: Dave promises it will be out soon)</p>
<p>You can learn more about creating snippets from the following sites:</p>
<ul>
<li><a href="http://msdn2.microsoft.com/en-us/library/ms165393%28en-us,VS.80%29.aspx">Creating Code Snippets</a> &mdash; Microsoft&rsquo;s How-To guide on creating basic and advanced snippets, including psuedo-clear explanations for Literal and Object replacements</li>
<li><a href="http://msdn2.microsoft.com/en-us/library/ms165392.aspx">Creating and Using Intellisense Code Snippets</a> &mdash; another Microsoft How-To for using and managing snippets</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://visualstudiohacks.com/code-snippets/snippy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
