Welcome to WindowsClient.net | Sign in | Join

BestSnowman's WPF Blog

Sponsors





  • advertise here

Visual Studio Snippets

I’m away from home and on my laptop and found out how much I miss my desktop setup, aside from tools like GhostDoc and StyleCop I have a couple of snippets that make things a little easier, unfortunately I’m had to recreate them from scratch to use them.

First off is the NotifyPropertyChanged property snippet based off of the VS 2005 prop snippet.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>NotifyPropertyChanged Property</Title>
      <Shortcut>nprop</Shortcut>
      <Description>Code snippet for NotifyPropertyChanged Property</Description>
      <Author>Snowman Consulting</Author>
      <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$ $property$
  {
    get
    {
          return $field$;
      }
    set
    {
          if($field$ != value)
          {
              $field$ = value;
              NotifyPropertyChanged("$property$");
          }
      }
  }
  $end$]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

Then two snippets I use with style cop, a copyright header that StyleCop likes and an auto generated one for files I don’t want StyleCop scanning.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>StyleCop Copyright</Title>
      <Shortcut>copyright</Shortcut>
      <Description>StyleCop Copyright</Description>
      <Author>Snowman Consulting</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet> 
      <Declarations>
        <Literal>
          <ID>filename</ID>
          <ToolTip>Filename</ToolTip>
          <Default>filename</Default>
        </Literal>
        <Literal>
          <ID>company</ID>
          <ToolTip>Company name</ToolTip>
          <Default>Snowman Consulting</Default>
        </Literal>
        <Literal>
          <ID>year</ID>
          <ToolTip>Copyright year</ToolTip>
          <Default>2009</Default>
        </Literal>
      </Declarations>
      <Code Language="csharp"><![CDATA[// <copyright file="$filename$.cs" company="$company$">
//     Copyright (c) $year$ $company$. All rights reserved.
// </copyright>
  $end$]]>
      </Code>
    </Snippet>
  </CodeSnippet>
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Auto-Generated</Title>
      <Shortcut>auto</Shortcut>
      <Description>Auto-generated comment</Description>
      <Author>Snowman Consulting</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="csharp"><![CDATA[// <auto-generated />$end$]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

Comments

No Comments

Page view counter