Automatic properties and replacing the Visual Studio 2008 ‘prop’ snippet

In .NET Framework 3.5, we’ve gained automatic properties. Automatic properties are really simple to understand. Instead of writing a full getter and setter with a private field (called a backing field, because it belongs to the property) you just write your property like this.

namespace ClassA.Examples.AutomaticProperties
  public class Customer
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string City { get; set; }

The compiler creates a ‘real’ property with a backing field, which you can view with Reflector or ildasm.


If you want more info, check out this blog entry by Bart de Smet.

Why I’m writing this, is because of the property snippet. I used to use the property snippet a lot, which produces some handy templated code. Visual Studio 2008 supports multi targeting and you can write software focused on the .NET Framework 2.0, 3.0 or 3.5.So you can develop an application without ever touching .NET Framework 3.5 or C# 3.0.Until you want to create properties… The new property snippet is based on the automatic properties in C# 3.0.

To solve this problem, first change the name of your original snippet from prop.snippet to aprop.snippet, where aprop stands for “automatic property”. You can find the property in the following folder, if installed at the default location.


Just changing the filename isn’t it though. Below is the copy of the original Visual Studio 2005 property snippet. Notice the Title and ShortCut elements. In your aprop.snippet you should change this accordingly. Then copy the code below and create a new prop.snippet in the same folder. That’s it.

<?xml version="1.0" encoding="utf-8" ?>
<codesnippets xmlns="">
  <codesnippet format="1.0.0">

      <description>Code snippet for VS2005 property and backing field</description>
      <author>Microsoft Corporation</author>

          <tooltip>Property type</tooltip>
          <tooltip>Property name</tooltip>
          <tooltip>The variable backing this property</tooltip>
      <code language="csharp"><![CDATA[private $type$ $field$;

  public $type$ $property$
    get { return $field$;}
    set { $field$ = value;}

UPDATE : That’s really funny, while writing this article, Daniel Moth was doing exactly the same… Well, not this one, but one a bit shorter. That’s why my article was posted half an hour later! 😉