Share via


Literal Element (IntelliSense Code Snippets)

Defines the literals of the code snippet that you can edit.

<CodeSnippets>
  <CodeSnippet>
    <Snippet>
      <Declarations>
        <Literal>

<Literal Editable="true/false">
   <ID>... </ID>
   <ToolTip>... </ToolTip>
   <Default>... </Default>
   <Function>... </Function>
</Literal>

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute

Description

Editable

Optional Boolean attribute.

Specifies whether or not you can edit the literal after the code snippet is inserted. The default value of this attribute is true.

Child Elements

Element

Description

Default

Required element.

Specifies the literal's default value when you insert the code snippet. There must be exactly one Default element in a Literal element.

Function

Optional element.

Specifies a function to execute when the literal receives focus in Visual Studio. There may be zero or one Function elements in a Literal element.

ID

Required element.

Specifies a unique identifier for the literal. There must be exactly one ID element in a Literal element.

Tooltip

Optional element.

Describes the expected value and usage of the literal. There may be zero or one Tooltip elements in a Literal element.

Parent Elements

Element

Description

Declarations

Contains the literals and objects of a code snippet that you can edit.

Remarks

The Literal element is used to identify a replacement for a piece of code that is entirely contained within the snippet, but will likely be customized after it is inserted into the code. For example, literal strings, numeric values, and some variable names should be declared as literals.

Literals and objects cannot contain an ID element with a value of selected or end. The value $selected$ represents text selected in the document that is to be inserted into the snippet when it is invoked. $end$ marks the location to place the cursor after the code snippet is inserted.

Example

The following code example shows how to declare a literal with an ID element value of SQL. The literal is referenced in the Code element by using the default delimiter. In this example, the literal is referenced with $SQL$.

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

See Also

Concepts

Code Snippets Schema Reference