Although the snippet is working, you still have a few things to polish. First, you have unnecessary line breaks above and below the inserted statement. Second, you defi nitely would not like to use the default message but rather should type the one fitting with the source code context. Before typing this custom message, select the default one. Now you must struggle a bit with whether to use either the mouse or the keyboard. Let ’ s remove these small pains and modify the < Snippet > section:
< ?xml version=”1.0” encoding=”utf-8”? >
< CodeSnippets xmlns=”http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet” >
< CodeSnippet Format=”1.0” >
< Header >
< Title > Write a message to the console < /Title >
< Shortcut > wmc < /Shortcut >
< Author >Your Name Here< /Author >
< Description >
This snippet inserts a “Console.WriteLine” invocation into the code.
< /Description >
< SnippetTypes >
< SnippetType > Expansion < /SnippetType >
< /SnippetTypes >
< /Header >
< Snippet >
< Declarations >
< Literal >
< ID > message < /ID >
< ToolTip > The message to write to the console < /ToolTip >
< Default > Message < /Default >
< /Literal >
< /Declarations >
< Code Language=”CSharp” >
< ![CDATA[Console.WriteLine(“$message$”);]] >
< /Code >
< /Snippet >
< /CodeSnippet >
< /CodeSnippets >
Note the addition of a < Declarations > section to the < Snippet > section defining a literal
parameter named message . Also note that the Code element has been modified by removing the
unnecessary line breaks and adding a reference to the message literal enclosed in dollar signs.
Save and import the modified snippet declaration again. The Code Snippets Manager recognizes
that you are importing a snippet file that has already been added to the folder. It pops up a dialog
to enable you to decide whether you want to rename or overwrite, or maybe skip it. Choose to
overwrite, and the modified snippet will replace the original one.Let ’ s try that out. After typing “ wmc ” and pressing the Tab key twice, the snippet ’ s code is inserted and the “ Message ” text is automatically selected, allowing you to replace it with the text you type in.
No comments:
Post a Comment