navigation
 Wednesday, May 23, 2007

Visual Studio comes with some handy (and some not-so-handy) code snippets, but for some reason there isn't one for declaring a method. It isn't that big of a deal, but after a while you might start resenting finishing your method header, then having to type Enter, {, Enter, }, Up, Enter to start the method body. Here's a snippet that will automatically put an open and closing brace after your method declaration, with the cursor ready to go in between:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>method</Title>
      <Shortcut>m</Shortcut>
      <Description>Code snippet for methods</Description>
      <Author>Adam Anderson</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>method-modifiers</ID>
          <ToolTip>Method modifiers</ToolTip>
          <Default>public</Default>
        </Literal>
        <Literal>
          <ID>return-type</ID>
          <ToolTip>Return type</ToolTip>
          <Default>void</Default>
        </Literal>
        <Literal>
          <ID>member-name</ID>
          <ToolTip>Method name</ToolTip>
          <Default>Name</Default>
        </Literal>
        <Literal>
          <ID>param-list</ID>
          <ToolTip>Parameter list</ToolTip>
          </Default>
        </Literal>
      </Declarations>
      <Code Language="csharp">
        <![CDATA[$method-modifiers$ $return-type$ $member-name$( $param-list$ )
{
$end$
}]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, i, strike, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview