Last active
January 3, 2019 16:20
-
-
Save howellcc/22f733b72f6dff465f920b1101415aa0 to your computer and use it in GitHub Desktop.
Visual Studio snippet for creating properties that include OnPropertyChanged
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
File needs to be placed in C:\Users{username}\Documents\Visual Studio 2017\Code Snippets\Visual C#\My Code Snippets