Snipping databound properties

6 08 2010

Long time no see Internet! Hope your summer has been as good as mine and that you’re at least as caffeinated and motivated as I am.

1280965856882Snippets are almost as tasty as bacon, and less calories

I just learned about snippets and wanted to share this wonderful coding aid with everyone. Let’s Go!

What are snippets? They sound delicious!

Snippets are a form of coding aid in Visual Studio. They’re XML based and if you’ve every typed “prop”, “if” or “propd” and then double-tabbed, you’ve already used them. Snippets give us a way to create big amounts of pre-defined code with a mere shortcut. This is great for reusable parts of programs.

Instead of going through every part of a snippet, I’m just going to show one that I made.

Let’s have a look before we begin (720p resolution please):

Let’s have it then..

<CodeSnippets xmlns=""> 

  <CodeSnippet Format="1.0.0"> 

This initial area isn’t much fun, very copy+pastable. The two things you might want to change here are the title and shortcut. The shortcut represents the commando you would use in VS2010 to create the codeblock.


Above in the <imports> tag, I’ve decided to import the namespace System.ComponentModel every time I insert this codeblock since it’s dependant on the namespace.

          <ToolTip>Replace with an object type.</ToolTip> 
          <ToolTip>Replace with initial-uppercase Name.</ToolTip> 
          <ToolTip>Replace with initial lowercase name.</ToolTip> 

Here I declare three literals. These are used in the code below to allow the user to customize the code. Using one or two literals really makes for powerful code generation.

      <Code Language="CSharp"> 
        private $Type$ $name$; 
        public $Type$ $Name$ 
                return $name$; 
                $name$ = value; 

Everything inside “<![CDATA[ “ is just regular C# code with my literals inside of “$” signs. This snippet will generate a databindable property for me in no-time.

Zowie! How do I use this?

You’ll have to create an xml document in VS2010 and save it as someName.snippet. Then either use Visual Studio’s Snippet Manager under “Tools” to import them or just add your snippet to “My Snippets” folder.

Probably under “C:\Users\your name here\Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets”

then you should be ready to go. Easy as pie!

Would you like to know more? Microsoft has a good guide on snippets at


So hungry…




One response

6 08 2010
Keir Davis

You should try our Code Barrel product. It integrates directly with Visual Studio and has many more features than the built-in manager.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: