Chapter 12: Customizing the Development Environment

357

5.In addition to access, the code example in the preceding step includes variables for return, methodName, and paramList. Add Literal elements for each of these variables, where the ID is the variable name and the Default is set to return as void, methodName as MethodName, and paramList as int p1.

6.Save the file and name it meth.snippet. The next section will explain where to put the file, but for now put it in a location that you can remember so you can copy it later. BTW, the Save File dialog box has Snippet Files (*.snippet) for a Save A Type option, which you can use to ensure the snippet has the correct file extension.

You now have a workable snippet. Listing 12-2 shows the snippet in its entirety. Additionally, notice how each Literal has a Tooltip to help the user of the snippet fill in each data item. Also, notice that the Language attribute of the Code element is spelled csharp, rather than C#. These small nuances, such as the spelling for a language, could make the snippet file invalid. A good troubleshooting technique is to open a similar snippet predefined for VS, as described in the preceding section, and compare formats to see if you might have mistyped something. The next section will explain what to do with this snippet file so that you can begin using it.

Listing 12-2 A custom method snippet

<?xml version="1.0" encoding="utf-8"?> <CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com /VisualStudio/2005/CodeSnippet">

<Header>

<Title>Method Snippet</Title> <Author>Joe Mayo</Author> <Shortcut>meth</Shortcut> <Description>Create a New Method</Description> <SnippetTypes>

<SnippetType>SurroundsWith</SnippetType>

<SnippetType>Expansion</SnippetType>

</SnippetTypes>

</Header>

<Snippet>

<Declarations>

<Literal>

<ID>access</ID>

<Default>public</Default> <ToolTip>Access modifier</ToolTip>

</Literal>

Page 380
Image 380
Microsoft 9GD00001 manual 357, Listing 12-2 a custom method snippet