elberon5.com

Snippets

Posted by elberon5 Fri, 20 Apr 2007 13:55:00 GMT

I've been using snippets since I started using Visual Studio 2005. This is one of the best features of the IDE. Aside from all the built-in snippets you can write your own. For some reason I felt compelled to share this with the few readers I have of this blog. Uh. Who am I kidding, I mean with myself. The only reason I have this blog is to look back later and remember what I did.

Here's one I wrote that I use over and over again. It's for Event Handlers. Any recommendations on how to improve this one would be greatly appreciated. Copy the code below and save into a .snippet file in your My Docs/VS2k5/Code Snippets folder. Then when you're in VS2k5 hit Ctrl+K, Ctrl+X. Enjoy.

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0"	>
		<Header>
			<Title>EventHandler</Title>
		</Header>

		<Snippet>
			<Declarations>
				<Literal Editable="true">
					<ID>MethodName</ID>
					<Default>MethodName</Default>
				</Literal>
				<Literal Editable="true">
					<ID>Body</ID>
					<Default></Default>
				</Literal>
			</Declarations>
			<Code Language="CSharp">
				protected void $MethodName$(object sender, EventArgs e)
				{
					$Body$
				}
			</Code>
		</Snippet>
	</CodeSnippet>
</CodeSnippets>

Another favorite snippet of mine is the built in switch. For some reason, going between several languages always confuses me on the syntax of these.

Comments

  1. gentooflux said 2 days later:
    Looks like someone's been doing a lot of event bubbling. I'm jealous of you and your ability to use snippets in your IDE, being myself hopelessly tied to vs.net 2003. I've been making a lot of classes lately (complete with custom exceptions), and having to write out the full syntax for properties is killing my carpal tunnel. I have snippets in Emacs for my Ruby code, but then, are snippets really all that necessary in Ruby?

(leave url/email »)