I've settled on the following style of creating properties (with a backing field):
private _firstName;
public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
Given that the name of the property is similar to the name of the backing field, I've improved the built in prop
snippet to the following:
<?xml version="1.0"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>prop</Title>
<Author>Frank Rizzo</Author>
<Description>Code snippet for property and backing field - changed one (not the original).</Description>
<Shortcut>prop</Shortcut>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>int</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal>
<ID>field</ID>
<ToolTip>The variable backing this property</ToolTip>
<Default>myVar</Default>
</Literal>
</Declarations>
<Code Language="CSharp"><![CDATA[private $type$ _$field$;
public $type$ $field$
{
get { return _$field$;}
set { _$field$ = value;}
}
$end$
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
This works to a degree, but the casing of the backing field and the property name is always the same, where as in my convention, the backing field is camel-cased, where as the property name is pascal-cased.
So my question is this: does the snippet syntax have a way to change the first letter of the property, so that the snippet might comply with my convention?