CodeElement.IsCodeType Property

Definition

Indicates whether or not a CodeType object can be obtained from the CodeElement object.

public:
 property bool IsCodeType { bool get(); };
public:
 property bool IsCodeType { bool get(); };
[System.Runtime.InteropServices.DispId(6)]
public bool IsCodeType { [System.Runtime.InteropServices.DispId(6)] [System.Runtime.InteropServices.TypeLibFunc(1024)] get; }
[<System.Runtime.InteropServices.DispId(6)>]
[<get: System.Runtime.InteropServices.DispId(6)>]
[<get: System.Runtime.InteropServices.TypeLibFunc(1024)>]
member this.IsCodeType : bool
Public ReadOnly Property IsCodeType As Boolean

Property Value

A Boolean value indicating whether or not a CodeType object can be obtained from the CodeElement object.

Attributes

Examples

Sub IsCodeTypeExample(ByVal dte As DTE2)  

    ' NOTE: This example requires a reference to the System.Text   
    '       namespace.  

    ' Before running this example, open a code document from a project.  
    Dim item As ProjectItem = dte.ActiveDocument.ProjectItem  
    Dim sb As New StringBuilder  

    RecurseElements(item.FileCodeModel.CodeElements, 0, sb)  

    MsgBox(item.Name & " contains the following elements:" & vbCrLf & _  
        vbCrLf & sb.ToString())  

End Sub  

Sub RecurseElements(ByVal elems As CodeElements, _  
    ByVal level As Integer, ByVal sb As StringBuilder)  

    Dim elem As CodeElement  
    For Each elem In elems  
        ' Add element to the list of names.  
        sb.Append(" "c, level * 8)  
        sb.Append(elem.Name & " [" & elem.Kind.ToString() & "]" & _  
            vbCrLf)  

        ' Call this function recursively if element has children.  
        If elem.Kind = vsCMElement.vsCMElementNamespace Then  
            RecurseElements(CType(elem, CodeNamespace).Members, _  
                level + 1, sb)  
        ElseIf elem.IsCodeType Then  
            RecurseElements(CType(elem, CodeType).Members, _  
                level + 1, sb)  
        End If  
    Next  

End Sub  
public void IsCodeTypeExample(DTE2 dte)  
{  
    // NOTE: This example requires a reference to the System.Text   
    //       namespace.  

    // Before running this example, open a code document from a   
    // project.  
    ProjectItem item = dte.ActiveDocument.ProjectItem;  
    StringBuilder sb = new StringBuilder();  

    RecurseElements(item.FileCodeModel.CodeElements, 0, sb);  

    MessageBox.Show(item.Name + " contains the following elements:" +   
        Environment.NewLine + Environment.NewLine + sb.ToString());  
}  

void RecurseElements(CodeElements elems, int level, StringBuilder sb)  
{  
    foreach (CodeElement elem in elems)  
    {  
        // Add element to the list of names.  
        sb.Append(' ', level * 8);  
        sb.Append(elem.Name + " [" + elem.Kind.ToString() + "]" +   
            Environment.NewLine);  

        // Call this function recursively if element has children.  
        if (elem.Kind == vsCMElement.vsCMElementNamespace)  
            RecurseElements(((CodeNamespace)elem).Members,   
                level + 1, sb);  
        else if (elem.IsCodeType)  
            RecurseElements(((CodeType)elem).Members, level + 1, sb);  
    }  
}  

Remarks

True if a CodeType object can be obtained, otherwise returns False. If it is True, then you can query interface or cast it to a CodeType object. This is true when Kind is vsCMElementClass, vsCMElementInterface, vsCMElementDelegate, vsCMElementStruct, or vsCMElementEnum.

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