|
我在演講時(shí)發(fā)現(xiàn)這個(gè)功能也相當(dāng)有用,不用現(xiàn)場(chǎng)敲代碼,直接調(diào)出非常方便。Visual Studio 2010增強(qiáng)了自定義代碼段功能,使創(chuàng)建自定義代碼段的操作更加簡(jiǎn)單了。
有兩種類(lèi)型的代碼段:
◆在游標(biāo)中插入的Expansion自定義代碼段
◆圍繞選定代碼的SurroundsWith自定義代碼段
創(chuàng)建自定義代碼段
首先在項(xiàng)目中插入一個(gè)新的XML文件,取名為T(mén)ryCatchFinally.snippet,注意文件名的后綴是.snippet,然后在編輯器窗口點(diǎn)擊右鍵,選擇“插入代碼段”*“代碼段”,創(chuàng)建一個(gè)基本的XML代碼段模板,代碼如下:
<CodeSnippet Format="1.0.0"
xmlns="http://schemas.microsoft.com/VisualStudio2005/CodeSnippet">
<Header>
<Title>title</Title>
<Author>author</Author>
<Shortcut>shortcut</Shortcut>
<Description>description</Description>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>name</ID>
<Default>value</Default>
</Literal>
</Declarations>
<Code Language="XML">
<![CDATA[<test>
<name>$name$</name>
$selected$ $end$</test>]]>
</Code>
</Snippet>
</CodeSnippet>
NET技術(shù):提高效率 用好Visual Studio 2010自定義代碼段,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。