Partilhar via


CodeNamespace.Members Property

Definition

Gets a collection of items contained by this CodeNamespace element.

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

Property Value

A CodeElements collection.

Attributes

Examples

Sub MembersExample(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)  

        ' Display the namespace members.  
        Dim members As String  
        Dim elem As CodeElement  
        For Each elem In spc.Members  
            members &= elem.Name & vbCrLf  
        Next  

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

End Sub  
public void MembersExample(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);  

        // Display the namespace members.  
        string members = "";  
        foreach (CodeElement elem in spc.Members)  
        {  
            members += elem.Name + Environment.NewLine;  
        }  

        MessageBox.Show(spc.Name + " has the following members:" + _  
            Environment.NewLine + Environment.NewLine + members);  
    }  
    catch (Exception ex)  
    {  
        MessageBox.Show(ex.Message);  
    }  
}  

Remarks

When the code type kind is vsCMElementDelegate, the Members method fails because delegates have no members in the source code. They are contributed by the compiler and the .NET Framework.

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