代码段

在vs的安装目录下的VC#\Snippets\2052\Visual C#中有很多,snipper文件,这就是vs的代码段文件,你可以在vs中敲下if然后看智能提示,上面提示的是if语句的代码段, 按下回车,再按Tab,就会插入代码 if (true) { } 我们可以在这个目录下面找到if.snipper文件,打开看看

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>if</Title>
<Shortcut>if</Shortcut>
<Description>if 语句的代码段</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>expression</ID>
<ToolTip>要计算的表达式</ToolTip>
<Default>true</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[if ($expression$)
{
$selected$ $end$
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

其实就是xml文件,鼠标放上各个节点会有各种提示,我就不多说了,我们也可以把这个结构赋值下来,然后写自己的代码段 节点是变量 我们不动他节点中中括号中的为按Tab键后显示的代码,我们给他改一改 然后在把上面改一下

<Header>
<Title>ifelse</Title>
<Shortcut>ifelse</Shortcut>
<Description>if~else 语句的代码段</Description>
<Author>MNight</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
然后把所有的代码保存成ifelse.snippet文件,在vs中敲下ifelse就会开到有if~else的代码段的提升,按回车再按tab就插入了
 if (true)
{

}
else
{

}
很方便

原文地址:https://www.cnblogs.com/mnight/p/1788627.html