VS的一些操作

设置用户片段 / 代码片段

  • vs页面 > 工具 > 代码片段管理器 > 随便找一个地址在里面放片段
  • 代码片段格式如下
    • <header>会显示在管理器里面, 其中<Shortcut>是触发片段的字段
    • <Literal>是用来解释变量的, 还应当设置默认值
    • $selected$ $end$这两个不知道为什么但总是一起出现
  • 此外, CDATA的格式不要变动, 在这之间的片段会按照原样式(也有可能是格式化之后的格式)输出
<?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>

tools

340 Words

0001-01-01 08:00 +0800