CodeClass2.Children 属性

定义

获取此代码类中所含的对象的集合。

public:
 property EnvDTE::CodeElements ^ Children { EnvDTE::CodeElements ^ get(); };
[System.Runtime.InteropServices.DispId(8)]
public EnvDTE.CodeElements Children { [System.Runtime.InteropServices.DispId(8)] [System.Runtime.InteropServices.TypeLibFunc(1024)] get; }
[<System.Runtime.InteropServices.DispId(8)>]
[<get: System.Runtime.InteropServices.DispId(8)>]
[<get: System.Runtime.InteropServices.TypeLibFunc(1024)>]
member this.Children : EnvDTE.CodeElements
Public ReadOnly Property Children As CodeElements

属性值

CodeElements

一个 CodeElements 集合。

实现

属性

示例

[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);  
    }  
}  

注解

如果代码类没有子级,则 Nothing null 返回或。

此属性主要由 Visual C++ 使用。 Children 从代码元素返回每个对象可再用。 例如,类返回成员、基、实现的接口、特性、注释等。

若要遍历命名空间的成员或类型 (类、结构、接口等) ,必须 () QI 查询接口,或者将转换 CodeElementCodeNamespace ,然后使用 Members 属性。

Children 返回 CodeElement 可通过代码类引用的所有相关对象的集合。 例如,这可能包括类的元数据代码元素,可能包括 Visual C++ declspecs,以及基于 Visual C++、模板参数等中的特性化编程功能提供的代码。

Children属性可能返回, Nothing 具体取决于对象和语言。 在 Visual Studio 中不需要支持此项。

备注

在进行了某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能变为非确定性的,这意味着不能确定它们的值始终保持不变。 有关详细信息,请参阅 "代码模型元素值在 使用代码模型查找代码时 可能发生变化" (Visual Basic) "。

适用于