Code Element (IntelliSense Code Snippets)
Provides a container the short code blocks of IntelliSense Code Snippets.
<Code Language="Language" Kind="method body/method decl/type decl/page/file/any" Delimiter="Delimiter"> Code to insert </Code>
The following sections describe attributes, child elements, and parent elements.
Specifies the delimiter used to describe literals and objects in the code. By default, the delimiter is $.
Specifies the kind of code that the snippet contains and, therefore, the location at which a code snippet must be inserted for the code snippet to compile. The values available are method body, method decl, type decl, file, and any. For more information, see the section "Kind Attribute" in the following table.
Specifies the language of the code snippet. The values available are VB, CSharp or XML. For more information, see the section "Language Attribute" in the following table.
Note The Intellisense Code Snippet schema does not support C++.
Specifies that the code snippet is a method body, and therefore, must be inserted inside a method declaration.
Specifies that the code snippet is a method, and therefore, must be inserted inside a class or module.
Specifies that the code snippet is a type, and therefore, must be inserted inside a class, module, or namespace.
Specifies that the snippet is a full code file. These code snippets can be inserted alone into a code file, or inside a namespace.
Specifies that the snippet can be inserted anywhere. This tag is used for code snippets that are context-independent, such as comments.
Identifies a Visual Basic code snippet.
Identifies a Visual C# code snippet.
Identifies an XML code snippet.
Contains the references, imports, declarations, and code for the code snippet.
Two reserved words are available for use in the text of the Code element: $end$ and $selected$. $end$ marks the location to place the cursor after the code snippet is inserted. $selected$ represents text selected in the document that is to be inserted into the snippet when it is invoked. For example, if you had:
$selected$ is a great color. I love $selected$.
and the word "Blue" was selected when you invoked the template, you would get:
Blue is a great color. I love Blue.
All other $ keywords are dynamically defined in the <Literal> and <Object> tags.
The Code element of the following code snippet shows how to write a Visual C# code snippet that creates a SqlDataAdapter. The literal and object defined in the Declarations element are referenced in the Code element by the value of their ID element. In this example, the literal is referenced as $SQL$ and the object is referenced as $Connection$.
<CodeSnippets xmlns="http://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>