Blog Home  Home Feed your aggregator (RSS 2.0)  
.Net Jonesie - My first Snippet
A simple programmers blog
 
# Tuesday, July 19, 2005

I'm not the most efficient coder.  Things like Resharper are a waste of time for me.  I prefer to repeat myself 4 million times rather than learn 23,000 keyboard shortcuts.  I think it's something to do with creative flow.

However, sometime you see things that are so easy and quick to use that you just adopt them without thinking.  Snippets are one of these.  David reminded me of this.

So, here's a custom snippet I created for inserting properties. This is pretty much the same as the default prop snippet, but I've added summary comments and I like my member vars to have a leading underscore:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
 <CodeSnippet Format="1.0.0">
  <Header>
   <Title>jprop</Title>
   <Shortcut>jprop</Shortcut>
   <Description>Code snippet for property and backing field</Description>
   <Author>Peter G Jones (modified version of prop from Microsoft Corporation)</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[/// <summary>
  /// Backing variable for property $property$
  /// </summary>     
  private $type$ $field$;
  /// <summary>
  /// Property $property$
  /// </summary>
 public $type$ $property$
 {
  get { return $field$;}
  set { $field$ = value;}
 }
 $end$]]>
   </Code>
  </Snippet>
 </CodeSnippet>
</CodeSnippets>

I can see that creating more elaborate snippets is pretty easy.  I wonder if it would be possible to have CodeSmith snippets?  That would be really cool!

Tuesday, July 19, 2005 7:23:45 AM (New Zealand Standard Time, UTC+12:00)  #    Comments [1]   Visual Studio  | 
Tuesday, July 19, 2005 11:34:44 PM (New Zealand Standard Time, UTC+12:00)
Wow thanks Peter, excellent time saver...
Comments are closed.
Copyright © 2012 Peter G Jones. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: