다음을 통해 공유


Snippet 요소(IntelliSense 코드 조각)

코드 조각에 대한 참조, 가져오기, 선언 및 코드를 지정합니다

<Snippet>
    <References>... </References>
    <Imports>... </Imports>
    <Declarations>... </Declarations>
    <Code>... </Code>
</Snippet>

특성 및 요소

다음 단원에서는 특성, 자식 요소 및 부모 요소에 대해 설명합니다.

특성

없음

자식 요소

요소

설명

코드

필수적 요소입니다.

설명서 파일에 삽입할 코드를 지정합니다. Snippet 요소에 Code 요소가 하나만 있어야 합니다.

선언

선택적 요소입니다.

편집할 수 있는 코드 조각의 일부를 구성하는 리터럴과 개체를 지정합니다. Snippet 요소에 Declarations 요소가 0개 이상 있을 수 있습니다.

Imports

선택적 요소입니다.

개별 Import 요소를 그룹화합니다. Snippet 요소에 Imports 요소가 0개 이상 있을 수 있습니다.

참조

선택적 요소입니다.

개별 Reference 요소를 그룹화합니다. Snippet 요소에 References 요소가 0개 이상 있을 수 있습니다.

부모 요소

요소

설명

CodeSnippet

하나의 제목과 여러 개의 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>

참고 항목

개념

코드 조각 스키마 참조