更新:2007 年 11 月
指定用于代码段的引用、导入、声明和代码。
<Snippet>
    <References>... </References>
    <Imports>... </Imports>
    <Declarations>... </Declarations>
    <Code>... </Code>
</Snippet>
属性和元素
以下几节描述了属性、子元素和父元素。
属性
无。
子元素
| 元素 | 说明 | 
|---|---|
| 必需。 指定要插入到文档文件中的代码。 Snippet 元素中必须有且仅有一个 Code 元素。 | |
| 可选。 指定构成代码段可编辑部分的文本和对象。 Snippet 元素中可能有零个或一个 Declarations 元素。 | |
| 可选。 对各个 Import 元素进行分组。 Snippet 元素中可能有零个或一个 Imports 元素。 | |
| 可选。 对各个 Reference 元素进行分组。 Snippet 元素中可能有零个或一个 References 元素。 | 
父元素
| 元素 | 说明 | 
|---|---|
| 允许您指定一个标题和多个 IntelliSense 代码段,这些代码段可插入到 Visual Studio 代码文件中。 | 
示例
下面的代码演示如何使用 Snippet 元素及其子元素编写创建 SqlDataAdapter 的 Visual C# 代码段。
<CodeSnippets xmlns="https://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Create a data adapter</Title>
            <Description>Creates a SqlDataAdapter object.</Description>
            <Author>Microsoft Corporation</Author>
            <Shortcut>createadapter</Shortcut>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>SQL</ID>
                    <ToolTip>Replace with a SQL connection string.</ToolTip>
                    <Default>"SQL connection string"</Default>
                </Literal>
                <Object>
                    <ID>Connection</ID>
                    <Type>System.Data.SqlClient.SqlConnection</Type>
                    <ToolTip>Replace with a connection object in your application.</ToolTip>
                    <Default>dcConnection</Default>
                </Object>
            </Declarations>
            <Code Language="CSharp">
                <![CDATA[
                    daCustomers = new SqlClient.SqlDataAdapter();
                    selectCommand = new SqlClient.SqlCommand($SQL$);
                    daCustomers.SelectCommand = selectCommand;
                    daCustomers.SelectCommand.Connection = $Connection$;
                ]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>