次の方法で共有


CodeClass2.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 は、コード要素から返すことができるすべてのオブジェクトを返します。 たとえば、クラスの場合は、メンバー、ベース、実装されたインターフェイス、属性、コメントなどを返します。

特定の名前空間またはタイプ (クラス、構造体、インターフェイスなど) のメンバーを反復処理するには、インターフェイスのサポートの有無を確認するか CodeElementCodeNamespace にキャストしてから、Members プロパティを使用する必要があります。

Children は、コード クラスを通じて参照できる、関連付けられたすべての CodeElement オブジェクトのコレクションを返します。 たとえば、Visual C++ の属性付きプログラミング機能に基づいて提供されたコードやテンプレート パラメーターなどに加えて、クラスのメタデータ コード要素や、Visual C++ の declspec などが含まれます。

オブジェクトや言語によっては、Children プロパティが Nothing を返す場合もあります。 Visual Studio でこれをサポートするための要件は特にありません。

注意

特定の種類の編集を行った後に、クラス、構造体、関数、属性、デリゲートなどのコード モデル要素の値を決定できないことがあります。つまり、これらの要素の値は、信頼できる値ではなく、常に同じ値になるとは限りません。詳細については、「コード モデルを使用したコードの調査 (Visual Basic)」で、コード モデル要素値を変更する方法についての説明を参照してください。

[Visual Basic]

Sub ChildrenExample(ByVal dte As DTE2)
    ' 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.
        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

[C#]

public void ChildrenExample(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 セキュリティ

  • 直前の呼び出し元に対する完全な信頼。このメンバーは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

関連項目

CodeClass2 インターフェイス

EnvDTE80 名前空間

その他の技術情報

方法 : オートメーション オブジェクト モデルのコード例をコンパイルおよび実行する

コード モデルを使用したコードの調査 (Visual Basic)

コード モデルを使用したコードの調査 (Visual C#)