Skip to content

Instantly share code, notes, and snippets.

@howellcc
Last active January 3, 2019 16:20
Show Gist options
  • Save howellcc/22f733b72f6dff465f920b1101415aa0 to your computer and use it in GitHub Desktop.
Save howellcc/22f733b72f6dff465f920b1101415aa0 to your computer and use it in GitHub Desktop.
Visual Studio snippet for creating properties that include OnPropertyChanged
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Property With Change Event</Title>
<Shortcut>propn</Shortcut>
<Description>Code snippet for property that calls RaisePropertyChanged and XML description</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$ $property$
{
get { return this.$field$; }
set
{
if(this.$field$ != value)
{
this.$field$ = value;
OnPropertyChanged();
}
}
}
$end$]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
@howellcc
Copy link
Author

howellcc commented Jan 3, 2019

File needs to be placed in C:\Users{username}\Documents\Visual Studio 2017\Code Snippets\Visual C#\My Code Snippets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment