CodeElement2 CodeElement2 CodeElement2 CodeElement2 CodeElement2 CodeElement2 Interface

Definition

Represents a code element or construct in a source file.

public interface class CodeElement2 : EnvDTE::CodeElement
public interface class CodeElement2 : EnvDTE::CodeElement
__interface CodeElement2 : EnvDTE::CodeElement
[System.Runtime.InteropServices.Guid("F03DCCE8-233B-43D7-A66B-A66EFC1F85C3")]
[System.Runtime.InteropServices.TypeLibType(4160)]
public interface CodeElement2 : EnvDTE.CodeElement
type CodeElement2 = interface
    interface CodeElement
Public Interface CodeElement2
Implements CodeElement
Attributes
Implements

Examples

[Visual Basic]

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  

[C#]

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

A code element can be any fragment of code, but generally, there is a CodeElement2 object for each definition or declarative syntax in a language. This means that for most top-level definitions or declarations in a file, or for any syntactic form in a class definition, and so forth, there is a corresponding CodeElement2 object.

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

Properties

Children Children Children Children Children Children

Gets a collection of objects contained within this CodeElement2.

Collection Collection Collection Collection Collection Collection

Gets the CodeElements collection containing the CodeElement2 that supports this property.

DTE DTE DTE DTE DTE DTE

Gets the top-level extensibility object.

ElementID ElementID ElementID ElementID ElementID ElementID

Gets a value that uniquely identifies the element. Not implemented in Visual C#.

EndPoint EndPoint EndPoint EndPoint EndPoint EndPoint

Gets the text point that is the location of the end of the code item.

Extender[String] Extender[String] Extender[String] Extender[String] Extender[String] Extender[String]

Returns the requested Extender if it is available for this CodeElement2 object. Not implemented in Visual C#.

ExtenderCATID ExtenderCATID ExtenderCATID ExtenderCATID ExtenderCATID ExtenderCATID

Gets the Extender category ID (CATID) for the CodeElement2 object. Not implemented in Visual C#.

ExtenderNames ExtenderNames ExtenderNames ExtenderNames ExtenderNames ExtenderNames

Gets a list of available Extenders for the CodeElement2 object. Not implemented in Visual C#.

FullName FullName FullName FullName FullName FullName

Gets the full path and name of the CodeElement2 object's file.

InfoLocation InfoLocation InfoLocation InfoLocation InfoLocation InfoLocation

Gets the capabilities of the code model.

IsCodeType IsCodeType IsCodeType IsCodeType IsCodeType IsCodeType

Gets whether or not a CodeType object can be obtained from the CodeElement2 object.

Kind Kind Kind Kind Kind Kind

Gets an enumeration that defines the type of code element.

Language Language Language Language Language Language

Gets the programming language that is used to author the CodeElement2.

Name Name Name Name Name Name

Gets or sets the name of the CodeElement2 object.

ProjectItem ProjectItem ProjectItem ProjectItem ProjectItem ProjectItem

Gets the ProjectItem object associated with the CodeElement object.

StartPoint StartPoint StartPoint StartPoint StartPoint StartPoint

Gets a TextPoint object that defines the beginning of the CodeElement2.

Methods

GetEndPoint(vsCMPart) GetEndPoint(vsCMPart) GetEndPoint(vsCMPart) GetEndPoint(vsCMPart) GetEndPoint(vsCMPart) GetEndPoint(vsCMPart)

Gets a TextPoint object that marks the end of the code element definition.

GetStartPoint(vsCMPart) GetStartPoint(vsCMPart) GetStartPoint(vsCMPart) GetStartPoint(vsCMPart) GetStartPoint(vsCMPart) GetStartPoint(vsCMPart)

Gets a TextPoint object that marks the beginning of the code element definition.

RenameSymbol(String) RenameSymbol(String) RenameSymbol(String) RenameSymbol(String) RenameSymbol(String) RenameSymbol(String)

Changes the declared name of an object and updates all code references to the object within the scope of the current project.

Applies to