Back

Visual Studio Snippet for Extension Methods

Extension method snippet

Extension methods

Using extension methods in Visual Studio can really help to reduce writing boilerplate code. Here's a simple snippet which can be used to create extension methods.

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>Extension Method</Title>
      <Author>Marc Duiker</Author>
      <Description>Snippet to create an extension method. 
      </Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>exm</Shortcut>
    </Header>
    <Snippet>
      <Declarations>
        <Literal Editable="true">
          <ID>TypeOut</ID>
          <ToolTip>TypeOut</ToolTip>
          <Default>TypeOut</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>MethodName</ID>
          <ToolTip>MethodName</ToolTip>
          <Default>MethodName</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>TypeIn</ID>
          <ToolTip>TypeIn</ToolTip>
          <Default>TypeIn</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>parameter</ID>
          <ToolTip>parameter</ToolTip>
          <Default>parameter</Default>
          <Function>
          </Function>
        </Literal>
      </Declarations>
      <Code Language="csharp"><![CDATA[public static $TypeOut$ $MethodName$(this $TypeIn$ $parameter$)
{
    $end$
}]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

Source

After importing the snippet via Tools > Code Snippets Manager you can use it by typing exm[TAB].