Fixing ‘prop’ Snippet Compatibility

As you might have gathered from reading my recent post on changing generated code in VS2008, I wasn’t thrilled when Microsoft changed the behavior of the prop snippet between VS2005 and VS2008. It’s almost two years later and my fingers still want to type 'prop’ even when I know that using automatic properties is very, very unlikely to be the thing that I want to generate.

My solution to this consternation was to create a custom snippet. The XML found below can be used to create such a snippet. In this case, the snippet is named ‘propfull’ and its template creates a property complete with the backing variable. It can be loaded into Visual Studio by using the Import button found in the Tools | Code Snippet Manager dialog box. The other possible approach would be to edit the snippet that comes with VS2008, but I’m loath to make that type of change to the default. Changing behavior that others have come to expect would evil, wouldn’t it Microsoft?

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="">
    <CodeSnippet Format="1.0.0">
            <Description>Code snippet for property implemented using a backing store</Description>
            <Author>Bruce Johnson, ObjectSharp Consulting</Author>
                    <ToolTip>Property type</ToolTip>
                    <ToolTip>Backing variable name</ToolTip>
                    <ToolTip>Property name</ToolTip>
            <Code Language="csharp"><![CDATA[
private $type$ $backing$;           
public $type$ $property$
   get { return $backing$; }
   set { $backing$ = value; }