다음을 통해 공유


CodeAttribute2.Children 속성

이 코드 구문에 포함된 개체의 컬렉션을 가져옵니다.

네임스페이스:  EnvDTE80
어셈블리:  EnvDTE80(EnvDTE80.dll)

구문

‘선언
ReadOnly Property Children As CodeElements
CodeElements Children { get; }
property CodeElements^ Children {
    CodeElements^ get ();
}
abstract Children : CodeElements with get
function get Children () : CodeElements

속성 값

형식: CodeElements
CodeElements 컬렉션을 반환합니다.

설명

개체에 자식이 없으면 Nothing이나 nullNull 참조(Visual Basic의 경우 Nothing)이 반환됩니다.

이 속성은 주로 Visual C++에서 사용됩니다. Children 속성은 코드 요소에서 반환 가능한 모든 개체를 반환합니다. 예를 들어, 클래스는 멤버, 기본, 구현된 인터페이스, 특성, 주석 등을 반환합니다.

형식 또는 네임스페이스의 여러 멤버(클래스, 구조체, 인터페이스 등)를 반복하려면 QI(인터페이스 쿼리)하거나 CodeElement 개체를 CodeNamespace 개체로 캐스팅한 다음 Members 속성을 사용해야 합니다.

Children 속성은 이 코드 요소를 통해 참조할 수 있는 관련된 모든 CodeElement2 개체의 컬렉션을 반환합니다. 예를 들어 CodeClass2 개체의 경우, 여기에는 클래스의 메타데이터 코드 요소, Visual C++ declspec, Visual C++에서 특성을 사용하는 프로그래밍 기능이 적용된 코드, 템플릿 매개 변수 등이 포함될 수 있습니다. CodeFunction2 개체에는 모든 해당 매개 변수, 특성을 사용하는 프로그래밍 기능이 적용된 매개 변수 등이 포함될 수 있습니다.

Children 속성은 개체와 언어에 따라 Nothing이나 null 을 반환할 수 있습니다. Visual Studio에서 이 속성을 지원하기 위해 필요한 사항은 없습니다.

예제

다음 예제에서는 현재 클래스에 새 네임스페이스와 특성을 만들고 특성의 일부 속성을 나열합니다.

Sub Children2Example(ByVal dte As DTE2)
    ' Before running this example, open a code page of a project
    ' and place the insertion point inside a namespace definition.
    Try
        ' Retrieve the CodeNamespace at the insertion point.
        Dim sel As TextSelection = _
            CType(dte.ActiveDocument.Selection, TextSelection)
        Dim spc As CodeNamespace = _
            CType(sel.ActivePoint.CodeElement( _
            vsCMElement.vsCMElementNamespace), CodeNamespace)

        ' Find the namespace's children.
        Dim children As String
        Dim elem As CodeElement
        For Each elem In spc.Children
            children &= elem.Name & vbCrLf
        Next

        MsgBox(spc.Name & " has the following child code elements:" & _
            vbCrLf & vbCrLf & children)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
public void Children2Example(DTE2 dte)
{
    // Before running this example, open a code document from a project
    // and place the insertion point inside a namespace definition.
    try
    {
        // Retrieve the CodeNamespace at the insertion point.
        TextSelection sel = 
            (TextSelection)dte.ActiveDocument.Selection;
        CodeNamespace spc = 
            (CodeNamespace)sel.ActivePoint.get_CodeElement(
            vsCMElement.vsCMElementNamespace);

        // Find the namespace's children.
        string children = "";
        
        foreach (CodeElement elem in spc.Children)
        children += elem.Name + "\r\n";

        MessageBox.Show(spc.Name + 
            " has the following child code elements:" + "\r\n\r\n" + 
            children);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 보안

참고 항목

참조

CodeAttribute2 인터페이스

EnvDTE80 네임스페이스

기타 리소스

방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행

코드 모델을 사용하여 코드 검색(Visual Basic)

코드 모델을 사용하여 코드 검색(Visual C#)