<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://robzyc.spaces.live.com/mmm2008-07-24_12.50/rsspretty.aspx?rssquery=en-US;http%3a%2f%2frobzyc.spaces.live.com%2fcategory%2fVisual%2bStudio%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The Ramblings of Rob Cooper: Visual Studio</title><description /><link>http://robzyc.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=catVisual%2bStudio</link><language>en-US</language><pubDate>Tue, 23 Sep 2008 05:29:29 GMT</pubDate><lastBuildDate>Tue, 23 Sep 2008 05:29:29 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://robzyc.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>5173604217493655657</live:id><live:alias>robzyc</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>Visual Studio Code Snippets - Part 2 - Creating Code Snippets</title><link>http://robzyc.spaces.live.com/Blog/cns!47CC559FF82C1069!571.entry</link><description>&lt;p&gt;Following on from my &lt;a href="http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!548.entry" target="_blank"&gt;previous post&lt;/a&gt; on code snippets, here's instalment two! In this part, I want to guide you through creating your own basic code snippets, in part three, we will cover a few &amp;quot;advanced&amp;quot; features of code snippets. &lt;p&gt;To avoid any confusion, I will demo everything in &lt;strong&gt;Visual Studio 2005&lt;/strong&gt; since 2008 has a few features that may take us away from what we are doing here. &lt;h2&gt;Creating a Code Snippet&lt;/h2&gt; &lt;p&gt;Snippets are basically just &lt;a href="http://en.wikipedia.org/wiki/XML" target="_blank"&gt;XML&lt;/a&gt; files that contain some code and &lt;a href="http://en.wikipedia.org/wiki/Metadata" target="_blank"&gt;metadata&lt;/a&gt;. As covered in the &lt;a href="http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!548.entry" target="_blank"&gt;introductory post&lt;/a&gt;, the code is inserted when you type the shortcut into Visual Studio. The XML files are then stored in &amp;quot;My Code Snippets&amp;quot; (or another folder of your choosing) for use by the IDE. There are a number of ways to create these XML files, and I will talk you through a couple of them. &lt;h3&gt;Good Ol' Fashioned Text Editor&lt;a href="http://8wnaqa.bay.livefilestore.com/y1pbcw0WaP087dln37JBZikK25HRoRxL9w3fj50zg1FRF7fjoKwpQRQL-cBCsgLc0_1_BrNhAE3IPDuEgbDEagIOg?PARTNER=WRITER"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px" height=130 alt=image src="http://by1.storage.msn.com/y1pqJPcYXlBrGMLsoQ5iAGeJ1-nzYB4JAR3Rz-mpbMCZw-EXGdHmmxG8EtGL_9daHETW5Wke_8OqzB0FM6BETAoAb_tPF9ESwtr?PARTNER=WRITER" width=244 align=right border=0&gt;&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;Obviously, XML is plain text and can be edited in Notepad, &lt;a href="http://www.flos-freeware.ch/notepad2.html" target="_blank"&gt;Notepad2&lt;/a&gt; (or your text editor of choosing). I like to use Notepad2 for my basic text editing, and here is a screen shot of my &amp;quot;ToDo&amp;quot; code snippet  within Notepad2: &lt;p&gt;As you can see, it looks pretty straightforward. I &lt;strong&gt;strongly&lt;/strong&gt; recommend that if you are going to create code snippets in this way, then you copy and paste and existing one and edit that. This makes sure you don't miss any details, and its obvious &amp;quot;what does what&amp;quot;. This is especially useful if you are new to code snippets. &lt;h3&gt;Snippy&lt;a href="http://by1.storage.msn.com/y1pqJPcYXlBrGOOa_yQVbNgKqSD5aMRB4M1IIlC1R3tukgNdtxBUEFfOMpWsqXTih2eho1B9IcPOhnDbzEkDuyEzUljitMpN12K?PARTNER=WRITER"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px" height=215 alt=image src="http://by1.storage.msn.com/y1pqJPcYXlBrGOyXLPHsiDKVFvuJd7FdkkVu0pUVu1mtfAI1na_2J79GminTw49W1k3jO_1BFy6k32z-d7KcaJw0V9cxGaNwfsa?PARTNER=WRITER" width=244 align=right border=0&gt;&lt;/a&gt; &lt;/h3&gt; &lt;p&gt;While using a text editor is fine, I find that when you are creating a lot of these, or trying to maintain them, then you start to get fed up with it. So I began &lt;a href="http://www.google.co.uk/search?q=&amp;quot;Code+Snippet&amp;quot;+Editor+&amp;quot;Visual+Studio&amp;quot;&amp;amp;ie=utf-8&amp;amp;oe=utf-8&amp;amp;aq=t&amp;amp;rls=org.mozilla:en-GB:official&amp;amp;client=firefox-a" target="_blank"&gt;searching the Internet for a code snippet editor&lt;/a&gt;. A Google returns a lot of results and I tried several until I found &lt;a href="http://www.codeplex.com/snippy" target="_blank"&gt;Snippy&lt;/a&gt;. Snippy is a lightweight, simple tool (now found on &lt;a href="http://www.codeplex.com" target="_blank"&gt;CodePlex&lt;/a&gt;). The screen shot to the right is the same &amp;quot;ToDo&amp;quot; code snippet in Snippy: &lt;p&gt;So, I found Snippy and stuck with it, I didn't want anything fancy, just something to make my life easier, so lets go through creating a code snippet in Snippy! &lt;h2&gt;Walkthrough&lt;/h2&gt; &lt;p&gt;&lt;strong&gt;NOTE: In the following scenario, I know I could use generic events etc. but I have opted for the explicit declarations so the code is clear to anyone unfamiliar with generics.&lt;/strong&gt; &lt;p&gt;OK, let's outline the scenario: &lt;p&gt; I don't know about you, but I create utility methods to raise my Events, since you need to check that the Event is not null, as well as possibly allowing the Event to be raised by subclasses of a superclass, such as the following: &lt;div style="border-right:gray 1px solid;padding-right:4px;border-top:gray 1px solid;padding-left:4px;font-size:8pt;padding-bottom:4px;margin:20px 0px 10px;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;line-height:12pt;padding-top:4px;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4"&gt; &lt;div style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;delegate&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; MyEventHandler();&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   2:&lt;/span&gt; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;event&lt;/span&gt; MyEventHandler MyEvent;&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   3:&lt;/span&gt;  &lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   4:&lt;/span&gt; &lt;span style="color:#008000"&gt;// event can only be raised by this class.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   5:&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; RaiseMyEvent()&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   6:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   7:&lt;/span&gt;     &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (MyEvent != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   8:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   9:&lt;/span&gt;         MyEvent();&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  10:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  11:&lt;/span&gt; }&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  12:&lt;/span&gt;  &lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  13:&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Foo()&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  14:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  15:&lt;/span&gt;     &lt;span style="color:#008000"&gt;// ... some stuff&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  16:&lt;/span&gt;     RaiseMyEvent();&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  17:&lt;/span&gt; }&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  18:&lt;/span&gt;  &lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  19:&lt;/span&gt; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;delegate&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; MyEventHandler2(EventArgs e);&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  20:&lt;/span&gt; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;event&lt;/span&gt; MyEventHandler2 MyEvent2;&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  21:&lt;/span&gt;  &lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  22:&lt;/span&gt; &lt;span style="color:#008000"&gt;// this event can be raised by this class, and subclasses.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  23:&lt;/span&gt; &lt;span style="color:#0000ff"&gt;protected&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; RaiseMyEvent2(EventArgs e)&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  24:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  25:&lt;/span&gt;     &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (MyEvent2 != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  26:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  27:&lt;/span&gt;         MyEvent2(e);&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  28:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  29:&lt;/span&gt; }&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  30:&lt;/span&gt;  &lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  31:&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Bar()&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  32:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  33:&lt;/span&gt;     &lt;span style="color:#008000"&gt;// some other stuff...&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  34:&lt;/span&gt;     RaiseMyEvent2(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; EventArgs());&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;  35:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;So as you can see, the code is pretty simplistic, and repetitive. This is an ideal example of when a code snippet would be useful.
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;Creating the Code Snippet in Snippy&lt;/h3&gt;
&lt;p&gt;So, lets make this into a code snippet! Fire up Snippy and you will be presented with a blank form. Enter the following info into the fields provided. These fields are pretty self-explanatory, but &amp;quot;Shortcut&amp;quot; deserves a special mention, this is the shortcut that you type in Visual Studio, so &lt;strong&gt;keep it short and understandable&lt;/strong&gt;:
&lt;p&gt;&lt;strong&gt;Title&lt;/strong&gt;: RaiseEvent Wrapper&lt;br&gt;&lt;strong&gt;Shortcut&lt;/strong&gt;: re&lt;br&gt;&lt;strong&gt;Author&lt;/strong&gt;: Your Name (&lt;em&gt;obviously replacing with your own name!&lt;/em&gt;)&lt;br&gt;&lt;strong&gt;Description&lt;/strong&gt;: Creates a wrapper method for raising an event. The method is marked as protected, allowing subclasses to raise the event. (&lt;em&gt;or whatever you feel is appropriate&lt;/em&gt;)
&lt;p&gt;Ignore the &amp;quot;namespaces&amp;quot; section, this doesn't seem to do anything (yet).
&lt;h3&gt;Literals and Objects&lt;/h3&gt;
&lt;p&gt;The next section is the &amp;quot;Literals &amp;amp; Objects&amp;quot; section. So &amp;quot;what are these?&amp;quot; you ask. Well, in a code snippet you have replaceable values that you can tab through, as described in Part 1. Literals &amp;amp; Objects are these replaceable values, but they are each intended for different meanings.
&lt;p&gt;&lt;strong&gt;Literals&lt;/strong&gt; are should be things like text and values that exist within the code snippet and may be used after. So things like variable names, connection string etc. should be defined as Literals.
&lt;p&gt;&lt;strong&gt;Objects&lt;/strong&gt; are elements that are normally defined outside of the code snippet, such as Forms, controls. Object references require that the type is specified.
&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: Snippy makes no differentiation between Literals and Objects and treats them equally (i.e. no type specification. I have suffered no negative side-effects of just defining everything as &amp;quot;Literal&amp;quot; although of I have yet to investigate this to see the difference between the two (added to ToDo!).
&lt;p&gt;I often find that it is easier to complete this section after writing the code, so lets go ahead and put the code in first.
&lt;h3&gt;The Code&lt;/h3&gt;
&lt;p&gt;Paste in the following base code taken from the above sample into the big text box in the &amp;quot;Code&amp;quot; section:
&lt;div style="border-right:gray 1px solid;padding-right:4px;border-top:gray 1px solid;padding-left:4px;font-size:8pt;padding-bottom:4px;margin:20px 0px 10px;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;line-height:12pt;padding-top:4px;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4"&gt;
&lt;div style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff"&gt;protected&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; RaiseMyEvent2(EventArgs e)&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   3:&lt;/span&gt;     &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (MyEvent2 != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   5:&lt;/span&gt;         MyEvent2(e);&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   6:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;OK, first off, we need to identify what elements of the code are going to change when we use it, from the RaiseEvent code, we will need to change:
&lt;ul&gt;
&lt;li&gt;The method name to &amp;quot;Raise&lt;em&gt;EventName&lt;/em&gt;&amp;quot;, where &amp;quot;EventName&amp;quot; is the name of the event we are raising.
&lt;li&gt;&amp;quot;EventArgs&amp;quot; to the type name of the EventArgs that we are passing.
&lt;li&gt;&amp;quot;MyEvent2&amp;quot; (in both parts of  the &amp;quot;if&amp;quot; statement to the Event name.&lt;/ul&gt;
&lt;p&gt;So, we essentially need two pieces of information, the event name, and the EventArgs type. It would also be useful if the &amp;quot;EventArgs&amp;quot; type defaulted to &amp;quot;EventArgs&amp;quot; since all classes should derive from this.
&lt;p&gt;So we know what we need to replace, so before we need to set the placeholders within the code that will later be replaced by the customised values. You do this by adding an ID to the code, surrounded in dollar symbols ($). As with code, name your values appropriately. We will call our placeholder ID's &amp;quot;$name$&amp;quot; and &amp;quot;$argstype$&amp;quot;. Edit the code in the &amp;quot;Code&amp;quot; TextBox to:
&lt;div style="border-right:gray 1px solid;padding-right:4px;border-top:gray 1px solid;padding-left:4px;font-size:8pt;padding-bottom:4px;margin:20px 0px 10px;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;line-height:12pt;padding-top:4px;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4"&gt;
&lt;div style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff"&gt;protected&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Raise$name$($argstype$ e)&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   3:&lt;/span&gt;     &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; ($name$ != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   5:&lt;/span&gt;         $name$(e);&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   6:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;border-top-style:none;line-height:12pt;padding-top:0px;font-family:consolas, 'Courier New', courier, monospace;border-right-style:none;border-left-style:none;background-color:white;border-bottom-style:none"&gt;&lt;span style="color:#606060"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;As you can see, its pretty straightforward what is going on here, the placeholders defined will be replaced with the values we enter when using the code snippet in the IDE.
&lt;p&gt;Once the code has been entered, change the &amp;quot;Language&amp;quot; drop down list to whatever language the code is in. &lt;strong&gt;This is important&lt;/strong&gt; because Visual Studio will only allow you to use C# code snippets in C# source, C++ snippets in C++ source and so on.
&lt;p&gt;Now we need to go back to our Literals and Objects and define the Literals that we are going to be replacing.
&lt;h3&gt;Literals Revisited&lt;/h3&gt;
&lt;p&gt;Click the &amp;quot;Add&amp;quot; button to add a Literal, we will start with the Event Name.
&lt;p&gt;Enter the following into the fields provided and click &amp;quot;OK&amp;quot;:
&lt;p&gt;&lt;strong&gt;ID&lt;/strong&gt;: name&lt;br&gt;&lt;strong&gt;ToolTip&lt;/strong&gt;: Enter the name of the Event, as declared in &amp;quot;public event ...&amp;quot;&lt;br&gt;&lt;strong&gt;Default&lt;/strong&gt; &lt;strong&gt;Value&lt;/strong&gt;: EventName&lt;br&gt;&lt;strong&gt;Function&lt;/strong&gt;: [leave blank]&lt;br&gt;&lt;strong&gt;Declaration&lt;/strong&gt; Type: Select &amp;quot;Literal&amp;quot; from the drop-down list.&lt;br&gt;&lt;strong&gt;Ensure &amp;quot;Editable&amp;quot; is checked.&lt;/strong&gt;
&lt;p&gt;This tells the code snippet (or the IDE) that when creating the code snippet, any elements in the code block defined as &amp;quot;$name&amp;quot; will be replaced by what we enter. In Visual Studio, the text entered for ToolTip will be displayed, and it will default to &amp;quot;EventName&amp;quot;. The &amp;quot;Editable&amp;quot; flag indicates that we want to be able to tab through it and change it.
&lt;p&gt;That said, lets go ahead and define the Literal for the &amp;quot;argstype&amp;quot; element.
&lt;p&gt;&lt;strong&gt;ID&lt;/strong&gt;: argstype&lt;br&gt;&lt;strong&gt;ToolTip&lt;/strong&gt;: The Type name for the EventArgs class being used for this Event.&lt;br&gt;&lt;strong&gt;Default&lt;/strong&gt; &lt;strong&gt;Value&lt;/strong&gt;: EventArgs&lt;br&gt;&lt;strong&gt;Function&lt;/strong&gt;: [leave blank]&lt;br&gt;&lt;strong&gt;Declaration&lt;/strong&gt; Type: Select &amp;quot;Literal&amp;quot; from the drop-down list.&lt;br&gt;&lt;strong&gt;Ensure &amp;quot;Editable&amp;quot; is checked.&lt;/strong&gt;
&lt;p&gt;OK, that's it! We are done, lets go ahead and save the snippet!
&lt;h2&gt;Saving the Snippet&lt;/h2&gt;
&lt;p&gt;Click &lt;strong&gt;File &amp;gt; Save As&lt;/strong&gt;. Then navigate to where you want to save the code snippets, I recommend you save them in &lt;strong&gt;My Documents &amp;gt; Visual Studio 2005&lt;/strong&gt; &lt;em&gt;(or 2008)&lt;/em&gt;&lt;strong&gt; &amp;gt; Code Snippets &amp;gt; [&lt;em&gt;Language&lt;/em&gt;] &amp;gt; My Code Snippets&lt;/strong&gt;. As this folder is automatically monitored by the IDE for code snippets. Lets go ahead and name the file &amp;quot;RaiseEvent Wrapper Method&amp;quot;.
&lt;p&gt;Once saved, we can close Snippy and return to the Visual Studio IDE.
&lt;h2&gt;Using the Snippet&lt;/h2&gt;
&lt;p&gt;Simply go to the point in the code where you want to insert the code snippet and enter the shortcut and press &lt;strong&gt;TAB&lt;/strong&gt; twice, in this example, the shortcut was &amp;quot;re&amp;quot;, and here are the results:
&lt;p&gt;&lt;a href="http://8wnaqa.bay.livefilestore.com/y1pyT3IH2OCE533zi2E9hde8BmGY9RIh3MErFmGTg-DOR6lSQETm5eAzQ4kNRYsj9mX2XG8tCnEJA2pXn0Dqtm4tVwef_3lrOyf?PARTNER=WRITER"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px" height=100 alt=image src="http://8wnaqa.bay.livefilestore.com/y1pyT3IH2OCE511TrpiI54ZtsLmBDwcfZ8rmWCbkQUDKJp8R3dqjonrxiZAhzfB_u-9q0SvpUFHC6cYpGZgOE4eLUTkAmXujezJ?PARTNER=WRITER" width=644 border=0&gt;&lt;/a&gt;
&lt;p&gt;&lt;a href="http://by1.storage.msn.com/y1pqJPcYXlBrGNASrtbW88fQWoh2pkLRLAmUT8qJ1XUJNHxEhkSJu3L1UTK6nbQuke1zxbN5-7aPQzJdLJxUbsxKCf0-w0r5FL6?PARTNER=WRITER"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px" height=159 alt=image src="http://by1.storage.msn.com/y1pqJPcYXlBrGPsOoBpmp2Ms9VWLudvRtupHoRtYgrA6aCf_7XqCiIyadoK8m9IS-gblR1CmUVmYXYR2CE-G0qxCEEyh4__JKxC?PARTNER=WRITER" width=369 border=0&gt;&lt;/a&gt;  
&lt;p&gt;&lt;a href="http://by1.storage.msn.com/y1pqJPcYXlBrGMppon3toqFbAeTnlLUklfvLtJdLtqLuObW_Ar787xxSz8ypFLPo8nhAxcIn_jGiG61TUxz7MvFYW2laaI64RCO?PARTNER=WRITER"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px" height=162 alt=image src="http://by1.storage.msn.com/y1pqJPcYXlBrGMhhadD8C0PSW4wIsVU5_UjyJtJO35U3CCfluOM8aQFhcqUzz6VwW5L7nPy1cs1r2UkpdrpAdpH_Cw9taqZ59Tj?PARTNER=WRITER" width=358 border=0&gt;&lt;/a&gt; 
&lt;p&gt;Excellent! As you can see, we can then type over the &amp;quot;EventName&amp;quot; with our own event name, and TAB to and replace the EventArgs type definition (if required). This is an excellent example of not only boosting productivity for mundane code, but also enforcing naming conventions by using and adhering to templates.
&lt;p&gt;&lt;strong&gt;Points to Note:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Notice how the IDE only allows one &amp;quot;tabbable&amp;quot; placeholder and automatically updates the other references.
&lt;li&gt;If you duplicate shortcuts, Visual Studio will prompt you to select the appropriate shortcut (nice to see someone was thinking ahead!). This is great if you want to set up similar code blocks but keep the number of shortcuts to remember down (for example, another RaiseEvent block that takes no event args can share the &amp;quot;re&amp;quot; shortcut).&lt;/ul&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;So in this post we:
&lt;ul&gt;
&lt;li&gt;Looked at creating basic snippets to use within Visual Studio.
&lt;li&gt;Created a basic code snippet that creates a method to act as a wrapper for RaiseEvent calls.
&lt;li&gt;Then enabled us to customise the code block by defining our own Event name and EventArgs type.
&lt;li&gt;Looked at some of the key points when using code snippets, such as duplication of shortcuts and the number of tabbable placeholders.&lt;/ul&gt;
&lt;p&gt;In the next instalments of this series, we will look at some more advanced code snippets such as using functions and creating larger code blocks.
&lt;p&gt;I hope you found this post useful and as always, if you have any questions/comments, then please feel free to comment below!
&lt;p&gt;
&lt;div style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Visual Studio" rel=tag&gt;Visual Studio&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Code Snippet" rel=tag&gt;Code Snippet&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Productivity" rel=tag&gt;Productivity&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Code Block" rel=tag&gt;Code Block&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Snippy" rel=tag&gt;Snippy&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Share:&lt;/b&gt;  &lt;a href="http://digg.com/submit?phase=2&amp;amp;url=http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!571.entry&amp;amp;title=Visual Studio Code Snippets - Part 2 - Creating Code Snippets" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/digg14.png"&gt; digg it! &lt;/a&gt; |  &lt;a href="http://del.icio.us/post?url=http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!571.entry&amp;amp;;title=Visual Studio Code Snippets - Part 2 - Creating Code Snippets" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/deliciou4.png"&gt; del.icio.us &lt;/a&gt; |  &lt;a href="http://www.furl.net/store?s=f&amp;amp;to=0&amp;amp;u=http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!571.entry&amp;amp;ti=Visual Studio Code Snippets - Part 2 - Creating Code Snippets" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/furl4.png"&gt; furl &lt;/a&gt; |  &lt;a href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!571.entry&amp;amp;title=Visual Studio Code Snippets - Part 2 - Creating Code Snippets" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/live4.png"&gt; Live &lt;/a&gt; |  &lt;a href="http://technorati.com/faves/?add=http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!571.entry&amp;amp;title=Visual Studio Code Snippets - Part 2 - Creating Code Snippets" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/technora4.png"&gt; Technorati &lt;/a&gt; |  &lt;a href="http://www.facebook.com/share.php?src=bm&amp;amp;v=4&amp;amp;i=1206909586&amp;amp;u=http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!571.entry&amp;amp;t=Visual Studio Code Snippets - Part 2 - Creating Code Snippets" target="_blank"&gt;&lt;img src="http://i11.tinypic.com/626e0dk.gif"&gt; Facebook &lt;/a&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=5173604217493655657&amp;page=RSS%3a+Visual+Studio+Code+Snippets+-+Part+2+-+Creating+Code+Snippets&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=robzyc.spaces.live.com&amp;amp;GT1=robzyc"&gt;</description><comments>http://robzyc.spaces.live.com/Blog/cns!47CC559FF82C1069!571.entry#comment</comments><guid isPermaLink="true">http://robzyc.spaces.live.com/Blog/cns!47CC559FF82C1069!571.entry</guid><pubDate>Sat, 05 Apr 2008 08:35:00 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!571/comments/feed.rss</wfw:commentRss><wfw:comment>http://robzyc.spaces.live.com/Blog/cns!47CC559FF82C1069!571.entry#comment</wfw:comment><dcterms:modified>2008-04-05T10:23:07Z</dcterms:modified></item><item><title>Visual Studio Code Snippets - Part 1 - Using Code Snippets</title><link>http://robzyc.spaces.live.com/Blog/cns!47CC559FF82C1069!548.entry</link><description>&lt;p&gt;I recently read &lt;a href="http://peterlanoie.blogspot.com/2008/03/c-prop-shortcut-in-visual-studio-2008.html" target="_blank"&gt;this blog post&lt;/a&gt; from &lt;a href="http://peterlanoie.blogspot.com" target="_blank"&gt;Peter Lanoie&lt;/a&gt;, a great guy who I met through &lt;a href="http://p2p.wrox.com" target="_blank"&gt;p2p.wrox.com&lt;/a&gt; about Visual Studio code snippets, it really got me thinking that I should post my own experiences to try and get more people into using them, and perhaps sharing their own snippets. &lt;h2&gt;&lt;/h2&gt; &lt;h2&gt;&lt;/h2&gt; &lt;h2&gt;A Code What?&lt;/h2&gt; &lt;p&gt;Not sure what a code snippet is? Well, a code snippet is simply some code that can be inserted into Visual Studio by typing a shortcut. These are designed to be time savers, as well as provide the added benefits of consistency of coding standards and style. &lt;p&gt;For example, lets take the most common, as mentioned in Peter's post, the property. &lt;p&gt;Whenever we write classes we need to define fields and properties to enable the outside world (code?) to access it. We can literally do hundreds of these over the course of a project. So it quickly becomes very annoying creating them. Situations like this are the ideal scenarios where a code snippet can save &lt;strong&gt;A LOT&lt;/strong&gt; of time. &lt;h2&gt;OK, Sounds Good, How Do I Use It?&lt;/h2&gt; &lt;p&gt;Inserting a code snippet is easy, thanks to Intellisense. As I said before, each code snippet can be assigned a shortcut, you simply type in this shortcut into your code, and Intellisense will pop up and let you know that you can insert a snippet, see the image, here I am inserting the '&lt;strong&gt;prop&lt;/strong&gt;' (Property) code snippet: &lt;p&gt;&lt;a href="http://by1.storage.msn.com/y1pqJPcYXlBrGOtP4hDtP-M8VWSFdlM0c7hthT1z3s8bkbVjFH3r7d01kGnBXL6ght7x5jd709oYd6U7-CgoK_WqvsHjH1z0z3O?PARTNER=WRITER"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px" height=163 alt=image src="http://by1.storage.msn.com/y1pqJPcYXlBrGM-3ROoFkhlyNU8o-Mos-776QtMQzlP2QPpAdNIjm3X4Nco8-_xz3M-uJ730uOdzTWnx12IYjw_QrgtZnIGme2Y?PARTNER=WRITER" width=504 border=0&gt;&lt;/a&gt; &lt;p&gt;Now, you are probably asking, &amp;quot;fine, I see the 'prop' and the nice Intellisense description, but where's my code?!&amp;quot; Good question, once the item code snippet is highlighted in Intellisense, you simply press &lt;strong&gt;TAB&lt;/strong&gt; twice to insert it, you then get the following: &lt;p&gt;&lt;a href="http://by1.storage.msn.com/y1pqJPcYXlBrGMbjN1THiaD8vaBlgXqa3vhngwWk0R7B6fhILVZ2OmiYs9BpWPW0wVbzVKywHKuf34MOP1LOJYDy3dOs2_RP1KB?PARTNER=WRITER"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px" height=38 alt=image src="http://by1.storage.msn.com/y1pqJPcYXlBrGOjXmJF9K-ijtnArb4Q1HiCrY78D8ggk9aBYkaqVSWXu5cp9L2SCrr_K8nA7jN0XLd9kB6js_XWmJLJNFfRNl8Q?PARTNER=WRITER" width=308 border=0&gt;&lt;/a&gt;  &lt;h2&gt;But I Don't Want an 'int' and I Don't Want It Called &amp;quot;MyProperty&amp;quot;!&lt;/h2&gt; &lt;p&gt;That's fine, they are just the defaults! As you may have noticed, the 'int' and 'MyProperty' are highlighted, this means that you can &lt;strong&gt;TAB&lt;/strong&gt; through them and replace their text. In my example, I want a string called 'Name', so I: &lt;ul&gt; &lt;li&gt;Type 'pro' (Intellisense picks it up the 'prop' as the closest match).  &lt;li&gt;I press &lt;strong&gt;TAB&lt;/strong&gt; twice. The code is inserted.  &lt;li&gt;I type 'string' and the 'int' is replaced.  &lt;li&gt;I press &lt;strong&gt;TAB&lt;/strong&gt; again and the cursor moves to 'My'Property' and selects it.  &lt;li&gt;I type 'Name' and 'MyProperty' is replaced.&lt;/ul&gt; &lt;p&gt;&lt;strong&gt;IMPORTANT NOTE:&lt;/strong&gt; I am using Visual Studio 2008 for this, which has automatic properties (which is what Peter's post was discussing), note, then you are using 2005, you also have the ability to tab over the private field declaration, as shown below: &lt;p&gt;&lt;a href="http://by1.storage.msn.com/y1pqJPcYXlBrGMnQrPj0yfuaYUSZ-VJiaooclxHRZTZWt9wqIj5HkSCyClVrj_2hU517ec3h4T5rPFitTR_zbmExORtJ7Y8MwZG?PARTNER=WRITER"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px" height=162 alt=image src="http://by1.storage.msn.com/y1pqJPcYXlBrGNBuVQ58jU_PcZQJJpYnDXPgx3Yqr7zAdi1n779qLxGyjs47WQ5JTTJoLAS7l6kapL3n-1lYtI_L0RSNJFuI5BY?PARTNER=WRITER" width=225 border=0&gt;&lt;/a&gt;  &lt;p&gt;Notice when you change the private field declaration, the values in the getter/setter change? Neat! &lt;p&gt;These are a &lt;strong&gt;powerful&lt;/strong&gt; part in your arsenal of weapons to help make you a more productive developer/programmer. &lt;strong&gt;Use Them!&lt;/strong&gt; One this I am always conscious of is &amp;quot;how long do I spend doing this, is this too long? Can I speed it up?&amp;quot;. If you find you are writing the same/similar blocks of code more than once/twice a day, it may well be an excellent candidate for a snippet. For example consider these scenarios: &lt;ul&gt; &lt;li&gt;Comment block headers.  &lt;li&gt;&amp;quot;ToDo&amp;quot; notes.  &lt;li&gt;Wrapper methods.  &lt;li&gt;Standard Exception type declarations.  &lt;li&gt;&amp;quot;Using&amp;quot; statements, of both types! (as in '&lt;strong&gt;using System&lt;/strong&gt;' and '&lt;strong&gt;using (Graphics g ...)&lt;/strong&gt;'  &lt;li&gt;Templates for double-buffered graphics.  &lt;li&gt;Data access code, query execution etc.&lt;/ul&gt; &lt;p&gt;Think about the common code that you type daily and whether or not it may be worth &amp;quot;snipping&amp;quot; it. &lt;p&gt;Remember, they are freely definable, in part two, I will go over how to create them! &lt;p&gt; &lt;div style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/visual studio" rel=tag&gt;visual studio&lt;/a&gt;,&lt;a href="http://technorati.com/tags/code snippet" rel=tag&gt;code snippet&lt;/a&gt;,&lt;a href="http://technorati.com/tags/productivity" rel=tag&gt;productivity&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Share:&lt;/b&gt;  &lt;a href="http://digg.com/submit?phase=2&amp;amp;url=http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!548.entry&amp;amp;title=Visual Studio Code Snippets - Part 1" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/digg14.png"&gt; digg it! &lt;/a&gt;|  &lt;a href="http://del.icio.us/post?url=http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!548.entry&amp;amp;;title=Visual Studio Code Snippets - Part 1" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/deliciou4.png"&gt; del.icio.us &lt;/a&gt;|  &lt;a href="http://www.furl.net/store?s=f&amp;amp;to=0&amp;amp;u=http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!548.entry&amp;amp;ti=Visual Studio Code Snippets - Part 1" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/furl4.png"&gt; furl &lt;/a&gt;|  &lt;a href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!548.entry&amp;amp;title=Visual Studio Code Snippets - Part 1" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/live4.png"&gt; Live &lt;/a&gt;|  &lt;a href="http://technorati.com/faves/?add=http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!548.entry&amp;amp;title=Visual Studio Code Snippets - Part 1" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/technora4.png"&gt; Technorati &lt;/a&gt;|  &lt;a href="http://www.facebook.com/share.php?src=bm&amp;amp;v=4&amp;amp;i=1206909586&amp;amp;u=http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!548.entry&amp;amp;t=Visual Studio Code Snippets - Part 1" target="_blank"&gt;&lt;img src="http://i11.tinypic.com/626e0dk.gif"&gt; Facebook &lt;/a&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=5173604217493655657&amp;page=RSS%3a+Visual+Studio+Code+Snippets+-+Part+1+-+Using+Code+Snippets&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=robzyc.spaces.live.com&amp;amp;GT1=robzyc"&gt;</description><comments>http://robzyc.spaces.live.com/Blog/cns!47CC559FF82C1069!548.entry#comment</comments><guid isPermaLink="true">http://robzyc.spaces.live.com/Blog/cns!47CC559FF82C1069!548.entry</guid><pubDate>Tue, 01 Apr 2008 20:40:00 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://robzyc.spaces.live.com/blog/cns!47CC559FF82C1069!548/comments/feed.rss</wfw:commentRss><wfw:comment>http://robzyc.spaces.live.com/Blog/cns!47CC559FF82C1069!548.entry#comment</wfw:comment><dcterms:modified>2008-04-05T10:24:03Z</dcterms:modified></item></channel></rss>