Share via


CodeNamespace.Members Property

Gets a collection of items contained by this CodeNamespace element.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

Syntax

'Declaration
ReadOnly Property Members As CodeElements
CodeElements Members { get; }
property CodeElements^ Members {
    CodeElements^ get ();
}
abstract Members : CodeElements with get
function get Members () : CodeElements

Property Value

Type: EnvDTE.CodeElements
A CodeElements collection.

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).

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

.NET Framework Security

See Also

Reference

CodeNamespace Interface

EnvDTE Namespace

Other Resources

How to: Compile and Run the Automation Object Model Code Examples

Discovering Code by Using the Code Model (Visual Basic)

Discovering Code by Using the Code Model (Visual C#)