vs2019 代码片段管理
工具/代码片段管理

上面地址是vs内部代码片段,可以参考写自定义片段
写好的模板保存为.snippet文件,放到固定文件夹中,然后使用添加,直接找到文件夹添加即可
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>代码片段管理器中显示名称</Title>
<Shortcut>nlog快捷键名称</Shortcut>
<Description>代码描述</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>name</ID>
<ToolTip>方法名</ToolTip>
<Default>MyMethod</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[
这里name会替换为上面定义的MyMethod
//public void $name$()
//{
Debug.Log("ngo");
//}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
for的模板
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>for</Title>
<Shortcut>for</Shortcut>
<Description>for 循环的代码片段</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>index</ID>
<Default>i</Default>
<ToolTip>索引</ToolTip>
</Literal>
<Literal>
<ID>max</ID>
<Default>length</Default>
<ToolTip>最大长度</ToolTip>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[for (int $index$ = 0; $index$ < $max$; $index$++)
{
$selected$ $end$
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
随意自定义的模板
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>me</Title>
<Shortcut>nlog</Shortcut>
<Description>TestNLogDescription</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Code Language="csharp"><![CDATA[
Debug.Log("ngo");
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

浙公网安备 33010602011771号