Skip to content

Instantly share code, notes, and snippets.

@howellcc
Created January 3, 2019 16:39
Show Gist options
  • Save howellcc/284dc3e811710f9d73929a5a60f3d29a to your computer and use it in GitHub Desktop.
Save howellcc/284dc3e811710f9d73929a5a60f3d29a to your computer and use it in GitHub Desktop.
Visual Studio text expansion snippet for private properties with public accessor
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Private Property With Public Accessor</Title>
<Shortcut>proppriv</Shortcut>
<Description>Code snippet for a private property with a public accessor.</Description>
<Author>howellcc</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>string</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal>
<ID>field</ID>
<ToolTip>Backing field name</ToolTip>
<Default>myProperty</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[private $type$ _$field$;
public $type$ $field$
{
get { return this._$field$; }
set
{
if(this._$field$ != value)
{
this._$field$ = value;
}
}
}
$end$]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment