CodeClass2.Children 屬性

取得這個程式碼類別內物件的集合。

命名空間:  EnvDTE80
組件:  EnvDTE80 (在 EnvDTE80.dll 中)

語法

'宣告
ReadOnly Property Children As CodeElements
    Get
CodeElements Children { get; }
property CodeElements^ Children {
    CodeElements^ get ();
}
abstract Children : CodeElements
function get Children () : CodeElements

屬性值

型別:EnvDTE.CodeElements
CodeElements 集合。

實作

CodeClass.Children

備註

如果程式碼類別沒有子系,則傳回 Nothing 或 nullNull 參照 (即 Visual Basic 中的 Nothing)。

這個屬性主要是由 Visual C++ 所用。 Children 會從程式碼項目傳回每個可傳回的物件。 例如,類別會傳回成員、基底、實作介面、屬性、註解等等。

若要逐一查看命名空間或型別 (類別、結構、介面等等) 的成員,則必須查詢介面 (QI) 或將 CodeElement 轉換成 CodeNamespace,然後再使用 Members 屬性。

Children 會傳回所有可以透過這個程式碼類別而參考的相關 CodeElement 物件之集合。 例如,這可能包括類別的中繼資料程式碼項目,甚至可能包括 Visual C++ 的 Declspec,以及依 Visual C++ 中的屬性化程式開發功能所提供的程式碼、範本參數等。

因物件和程式語言的不同,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 介面

Children 多載

EnvDTE80 命名空間

其他資源

HOW TO:編譯和執行 Automation 物件模型程式碼範例

使用程式碼模型探索程式碼 (Visual Basic)

使用程式碼模型探索程式碼 (Visual C#)