有趣的場景開始於您想用$ selected $創建兩次環繞聲片段。例如創建CheckArgumentForNull代碼片段來檢查參數爲null,如果是null,則引發具有參數名稱的ArgumentNullException。只有後來才被替換。
任何想法?當然,我們可以使用只擴展的片段並輸入參數名稱。
<?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>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
<Title>notnull</Title>
<Author>Viiar Consulting</Author>
<Description>Code snippet for checking whether is argument null</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>notnull</Shortcut>
</Header>
<Snippet>
<Imports>
<Import>
<Namespace>System</Namespace>
</Import>
</Imports>
<Declarations>
<Literal Editable="true">
<ID>argument</ID>
<ToolTip>
</ToolTip>
<Default>argument</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[if ($selected$ == null)
{
throw new ArgumentNullException("$selected$");
}
$end$]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
按下'ENTER'是執行此操作的正常方法,它完成插入代碼段的過程。 – Richard 2010-09-06 09:51:52