Partager via


CodeDelegate2.Children Property

Definition

Gets a collection of objects contained within this CodeDelegate2.

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

Property Value

A CodeElements collection.

Implements

Attributes

Examples

Before running this example, load a project with a class and insert the following line along with the example code. After both the line and the example code are added, click the Delegate line to place the insertion point there, and then run the example.

[VisualBasic]

Delegate Sub MySubDelegate(ByVal x As Integer)  

[C#]

public delegate void MySubDelegate(int x);  

[VisualBasic]

Public Sub CodeDelegateExample(ByVal dte As DTE2)  
    ' Before running this example, open a code document from a   
    ' project and place the insertion point inside a class   
    ' definition.  
    Try  
        ' Retrieve the CodeClass at the insertion point.  
        Dim sel As TextSelection = _  
            CType(DTE.ActiveDocument.Selection, TextSelection)  
        Dim del As CodeDelegate2 = _  
            CType(sel.ActivePoint.CodeElement( _  
        vsCMElement.vsCMElementDelegate), CodeDelegate2)  
        Dim elem As CodeElement2  
        Dim sb As New System.Text.StringBuilder  

        ' Display the baseclass name of the delegate.  
        sb.AppendLine("Delegate base class name: " & _  
          del.BaseClass.Name)  
        sb.AppendLine("Delegate's access: " & del.Access.ToString)  
        sb.AppendLine("Children: " & del.Children.Count & "  _  
          Name: " & del.Children.Item(1).Name)  
        sb.AppendLine("Collection: " & del.Collection.Count)  
        sb.AppendLine("Delegates:")  
        For Each elem In del.Collection  
            sb.AppendLine("    - " & elem.Name)  
        Next  
        sb.AppendLine("Comment: " & del.Comment)  
        sb.AppendLine("Doc Comment: " & del.DocComment)  
        sb.AppendLine("DTE Parent: " & del.DTE.Name)  
        sb.AppendLine("Endpoint location: " & _  
          del.EndPoint.AbsoluteCharOffset)  
        sb.AppendLine("Infolocation: " & del.InfoLocation.ToString)  
        sb.AppendLine("Can provide CodeType object? " & _  
          del.IsCodeType.ToString)  
        sb.AppendLine("Is Delegate derived? " & _  
          del.IsDerivedFrom("EnvDTE80"))  
        sb.AppendLine("Is Delegate a generic? " & del.IsGeneric)  
        sb.AppendLine("Kind: " & del.Kind.ToString)  
        sb.AppendLine("Authoring language: " & _  
          del.Language.ToString)  
        sb.AppendLine("Name: " & del.Name)  
        sb.AppendLine("Namespace: " + del.Namespace.Name);  
        sb.AppendLine("Parameters: " & del.Parameters.Item(1).Name)  
        sb.AppendLine("Project containing the delegate: " & _  
          del.ProjectItem.Name)  
        sb.AppendLine("Prototype for delegate: " & del.Prototype)  
        sb.AppendLine("Delegate start point offset: " & _  
          del.StartPoint.LineCharOffset)  
        sb.AppendLine("Type: " & del.Type.TypeKind.ToString)  
        MsgBox(sb.ToString)  

    Catch ex As System.Exception  
        MsgBox(ex.ToString)  
    End Try  
End Sub  

[C#]

public void CodeDelegateExample(DTE2 DTE)  
{  
    try  
    {  
        // Retrieve the CodeClass at the insertion point.  
        TextSelection sel = (TextSelection)   
          DTE.ActiveDocument.Selection;  
        CodeDelegate2 del = (CodeDelegate2)   
          sel.ActivePoint.get_CodeElement  
          (vsCMElement.vsCMElementDelegate);  
        System.Text.StringBuilder sb = new System.Text.StringBuilder();  
        // Display the baseclass name of the delegate.  
        sb.AppendLine("Delegate base class name: " +   
          del.BaseClass.Name);  
        sb.AppendLine("Delegate's access: " + del.Access);  
        sb.AppendLine("Children: "+del.Children.Count+"  Name:   
          "+del.Children.Item(1).Name);  
        sb.AppendLine("Collection: "+del.Collection.Count);  
        sb.AppendLine("Delegates:");  
        foreach (CodeElement2 elem in del.Collection )  
        {  
            sb.AppendLine("    - "+elem.Name);  
        }  
        sb.AppendLine("Comment: "+del.Comment);  
        sb.AppendLine("Attributes:");   
        foreach (CodeElement2 elem in del.Attributes)  
        {  
            sb.AppendLine("    - " + elem.Name);  
        }  
        sb.AppendLine("Bases:");  
        foreach (CodeElement2 elem in del.Bases)  
        {  
            sb.AppendLine("    - " + elem.Name);  
        }   
        sb.AppendLine("Doc Comment: " + del.DocComment);  
        sb.AppendLine("DTE Parent: "+del.DTE.Name);  
        sb.AppendLine("Endpoint location:   
          "+del.EndPoint.AbsoluteCharOffset);  
        sb.AppendLine("Infolocation: "+del.InfoLocation);  
        sb.AppendLine("Can provide CodeType object? "+del.IsCodeType);  
        sb.AppendLine("Is Delegate derived?   
          "+del.get_IsDerivedFrom("EnvDTE80"));  
        sb.AppendLine("Is Delegate a generic? "+del.IsGeneric);  
        sb.AppendLine("Kind: "+del.Kind);  
        sb.AppendLine("Authoring language: "+del.Language);  
        sb.AppendLine("Name: "+del.Name);  
        sb.AppendLine("Parameters: "+del.Parameters.Item(1).Name);  
        sb.AppendLine("Namespace: " + del.Namespace.Name);  
        sb.AppendLine("Project containing the delegate:   
          "+del.ProjectItem.Name);  
        sb.AppendLine("Delegate start point offset:   
          "+del.StartPoint.LineCharOffset);  
        sb.AppendLine("Type: "+del.Type.TypeKind);  
          MessageBox.Show(sb.ToString());  
    }  
    catch(System.Exception ex)  
    {  
        MessageBox.Show(ex.Message);  
    }  
}  

Remarks

If the delegate has no children, then Nothing is returned.

This property is used primarily by Visual C++. Children returns every object returnable from a code element. A class, for example, returns members, bases, implemented interfaces, attributes, comments, and so forth.

To iterate through the members of a namespace or type (class, struct, interface, and so forth), you must QI (query interface) or cast the CodeElement2 to a CodeNamespace and then use the Members property.

Children returns the collection of all related CodeElement2 objects that can be referenced via this delegate. For example, for a CodeClass, this might include the metadata code elements for the class and perhaps the Visual C++ declspecs, along with contributed code based on the Attributed Programming feature in Visual C++, template parameters, and so forth. A CodeFunction2 might include all of its parameters, contributed parameters based on the Attributed Programming feature in Visual C++, and so forth.

The Children property may return Nothing depending on the object and the language. There is no requirement to support this in Visual Studio.

Note

The values of code model elements such as classes, structs, functions, attributes, delegates, and so forth can be non-deterministic after making certain kinds of edits, meaning that their values cannot be relied upon to always remain the same. For more information, see the section Code Model Element Values Can Change in Discovering Code by Using the Code Model (Visual Basic).

Applies to