vs2019 代码片段管理

工具/代码片段管理

 

上面地址是vs内部代码片段,可以参考写自定义片段

写好的模板保存为.snippet文件,放到固定文件夹中,然后使用添加,直接找到文件夹添加即可

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?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的模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?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>

  

 

随意自定义的模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?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>

  

 

posted @   00000000O  阅读(151)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决
历史上的今天:
2020-07-22 标准差,绝对中位差
点击右上角即可分享
微信分享提示