CodeEnum.Members Property

 

Gets a collection of items contained by this enumeration.

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

CodeElements Members { get; }

Property Value

Type: EnvDTE.CodeElements

A CodeElements collection.

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

System_CAPS_noteNote

The values of code model elements, such as classes, structures, functions, attributes, delegates, cannot be relied upon to remain the same at all times. For more information, see the section Code Model Element Values Can Change in Discovering Code by Using the Code Model (Visual Basic).

The following example shows how to get the members of an enumeration.

[Visual Basic]

Sub GetMembersExample(ByVal dte As DTE2)
    ' Before running this example, open a code document from a project
    ' and place the insertion point inside an enumeration.
    Try
        ' Retrieve the CodeEnum at the insertion point.
        Dim sel As TextSelection = _
            CType(dte.ActiveDocument.Selection, TextSelection)
        Dim enm As CodeEnum = _
            CType(sel.ActivePoint.CodeElement( _
            vsCMElement.vsCMElementEnum), CodeEnum)

        ' Get the members of the enumeration.
        Dim elems As CodeElements
        elems = enm.Members
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

[C#]

public void GetMembersExample(DTE2 dte)
{
    // Before running this example, open a code document from a project
    // and place the insertion point inside an enumeration.
    try
    {
        // Retrieve the CodeEnum at the insertion point.
        TextSelection sel = 
            (TextSelection)dte.ActiveDocument.Selection;
        CodeEnum enm = 
            (CodeEnum)sel.ActivePoint.get_CodeElement(
            vsCMElement.vsCMElementEnum);

        // Get the members of the enumeration.
        CodeElements elems = enm.Members;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
Return to top
Show: