Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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"
    Code to insert






Optional attribute.

Specifies the delimiter used to describe literals and objects in the code. By default, the delimiter is $.


Optional attribute.

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.


Required attribute.

Specifies the language of the code snippet. For more information, see the section "Language Attribute".

Kind Attribute



method body

Specifies that the code snippet is a method body, and therefore, must be inserted inside a method declaration.

method decl

Specifies that the code snippet is a method, and therefore, must be inserted inside a class or module.

type decl

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.

Language Attribute




Identifies a Visual Basic code snippet.


Identifies a Visual C# code snippet.


Identifies an XML code snippet.


Identifies a C++ code snippet.


Identifies a JavaScript code snippet.


Identifies a Jscript code snippet.


Identifies a SQL code snippet.


Identifies an HTML code snippet.

Child Elements


Parent Elements




Contains the references, imports, declarations, and code for the code snippet.

A text value is required.

This text specifies the code, along with the literals and objects, that you can use when this code snippet is inserted into a project.

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$.

    <CodeSnippet Format="1.0.0">
            <Title>Create a data adapter</Title>
            <Description>Creates a SqlDataAdapter object.</Description>
            <Author>Microsoft Corporation</Author>
                    <ToolTip>Replace with a SQL connection string.</ToolTip>
                    <Default>"SQL connection string"</Default>
                    <ToolTip>Replace with a connection object in your application.</ToolTip>
            <Code Language="CSharp">
                    daCustomers = new SqlClient.SqlDataAdapter();
                    selectCommand = new SqlClient.SqlCommand($SQL$);
                    daCustomers.SelectCommand = selectCommand;
                    daCustomers.SelectCommand.Connection = $Connection$;
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.