The Artima Developer Community
Sponsored Link

.NET Buzz Forum
CodeGen and Visual Studio Snippets

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jonathan Crossland

Posts: 630
Nickname: jonathanc
Registered: Feb, 2004

Jonathan Crossland is a software architect for Lucid Ocean Ltd
CodeGen and Visual Studio Snippets Posted: Jan 29, 2009 5:16 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Jonathan Crossland.
Original Post: CodeGen and Visual Studio Snippets
Feed Title: Jonathan Crossland Weblog
Feed URL: http://www.jonathancrossland.com/syndication.axd
Feed Description: Design, Frameworks, Patterns and Idioms
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Jonathan Crossland
Latest Posts From Jonathan Crossland Weblog

Advertisement
Code Snippets in Visual Studio is a form of CodeGen.

You have a template and its injected into your editor. I modify these quite a bit, mainly because I like my properties to have fields with an underscore and named the same as the property:

Here is my Prop.snippet (found in Tools|Code Snippet Manager|C#
It is a little different as this one matches the variable name with the property, puts the brackets how I want them and also puts my _CamelCasedField name.

Also now with Visual Studio.NET 2008, we have a Code Snippet Editor to make life easier.
[code:c#]
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
      <CodeSnippet Format="1.0.0">
            <Header>
                  <Title>prop</Title>
                  <Shortcut>prop</Shortcut>
                  <Description>Code snippet for an automatically implemented property</Description>
                  <Author>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>
                  </Declarations>
                  <Code Language="csharp">
             <![CDATA[
private $type$ _$property$;

/// <summary>
/// 
/// </summary>
public $type$ $property$ 
{ 
  get
  {
    return _$property$;
  }
  set
  {
    _$property$ = value;
  }
}$end$]]>
                  </Code>
            </Snippet>
      </CodeSnippet>
</CodeSnippets>

[/code]


Yeah, I know its longer, and some like the bracket on the top line {
}
like that, but thats the way I like it. Who can argue?
I know someone who still prefixes everything with str_, int_ and so on. We are all different.

Round Trip Engineering (RTE) for Code Snippets

I believe, the next generation of code snippets, and CodeGen as a whole, should have rte capabilities. using Code snippets as an example, when we embed a code snippet, in our code, it should always understand that it was/is a code snippet.
That way we could change the variable and have it change the expression in the code snippet. In fact this is simply refactoring, but keeping the Expression and code snippet metadata is an important step.

Read: CodeGen and Visual Studio Snippets

Topic: How to Move Groove Data Files Previous Topic   Next Topic Topic: Understanding and Configuring BitLocker with TPM

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use