Udostępnij za pośrednictwem


Function Element (IntelliSense Code Snippets)

Specifies a function to execute when the literal or object receives focus in Visual Studio.

<CodeSnippets>
   <CodeSnippet>
     <Snippet>
       <Declarations>
         <Literal>
           <Function>
             <Object>
               <Function>

<Function>
    FunctionName
</Function>

Attributes and Elements

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

Attributes

None.

Child Elements

None.

Parent Elements

Element

Description

Literal

Defines the literal fields of the code snippet that you can edit.

Object

Defines the object fields of the code snippet that you can edit.

Text Value

A text value is required.

This text specifies a function to execute when the literal or object field receives focus in Visual Studio.

Remarks

The Function element is only supported in Visual C# code snippets. For a complete list of supported functions, see Code Snippet Functions.

Example

The following code example shows an example of the GenerateSwitchCases function. This function generates a case statement for each value in the enumeration specified in $expression$.

<CodeSnippets xmlns="https://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <!-- Insert Header information here. -->
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>expression</ID>
                    <ToolTip>Expression to switch on.</ToolTip>
                    <Default>switch_on</Default>
                </Literal>
                <Literal Editable="false">
                    <ID>cases</ID>
                    <Function>GenerateSwitchCases($expression$)</Function>
                    <Default>default:</Default>
                </Literal>
            </Declarations>
            <Code Language="CSharp">
                <![CDATA[
                    switch ($expression$)
                    {
                         $cases$
                    }
                ]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

See Also

Concepts

Code Snippets Schema Reference

Reference

Code Snippet Functions