Code Snippets in VS2008

A while ago, I started creating some snippets for things I do all the time. As a bare-minimum, here are a few I use pretty regularly:


Simply unzip the file, and put these in the following folder:

C:Users[USERNAME]DocumentsVisual Studio 2008Code SnippetsVisual C#My Code Snippets

These files include include:

propProperty – named this, so it shows up near the other “prop” snippets. This allows me to create a property with backing fields, that follows best-practices:

/// <summary>

/// Gets or sets …

/// </summary>

public string FirstName


    get { return _firstName; }

    set { _firstName = value; }

} private string _firstName;

but also, by putting the private field after the last curly brace, it allows me to roll-up the properties, and it looks like this:


so it keeps the backing field right with the property, nice-and-tidy!

exceptionProper – again, named this so it stays in the same area as “exception”. This creates a property Exception class with all the constructors and XML code comments.

unitTestClass – creates an MSTest compliant unit test class and sets up the structure properly, including XML code comments.

UnitTestMethod – creates an MSTest compliant unit test method.

unitTestExceptionConstructors – creates an MSTest compliant set of unit test methods to check the 3 public constructors that should exist for all exceptions.

I initially wanted to put this up here, so that I have them in a place where I can get to them in case I lose a hard drive. But also, these may be useful for others. So, if you think you might find these useful, feel free to download from the link above. Enjoy!

Posted in Best-practices, Uncategorized

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

%d bloggers like this: