FileCodeModel2.CodeElementFromPoint(TextPoint, vsCMElement) Methode

Definition

Gibt ein Codeelement an einem bestimmten Ort in einer Quelldatei zurück.

public:
 EnvDTE::CodeElement ^ CodeElementFromPoint(EnvDTE::TextPoint ^ Point, EnvDTE::vsCMElement Scope);
public:
 EnvDTE::CodeElement ^ CodeElementFromPoint(EnvDTE::TextPoint ^ Point, EnvDTE::vsCMElement Scope);
EnvDTE::CodeElement CodeElementFromPoint(EnvDTE::TextPoint const & Point, EnvDTE::vsCMElement Scope);
[System.Runtime.InteropServices.DispId(5)]
public EnvDTE.CodeElement CodeElementFromPoint (EnvDTE.TextPoint Point, EnvDTE.vsCMElement Scope);
[<System.Runtime.InteropServices.DispId(5)>]
abstract member CodeElementFromPoint : EnvDTE.TextPoint * EnvDTE.vsCMElement -> EnvDTE.CodeElement
Public Function CodeElementFromPoint (Point As TextPoint, Scope As vsCMElement) As CodeElement

Parameter

Point
TextPoint

Erforderlich. Ein TextPoint-Objekt, das die Editorposition darstellt, für die Sie ein Codeelement benötigen.

Scope
vsCMElement

Erforderlich. Eine vsCMElement-Konstante, die das Codeelement des angegebenen Typs darstellt, das die Editorposition enthält.

Gibt zurück

CodeElement

Ein CodeElement-Objekt.

Implementiert

Attribute

Beispiele

Sub CodeElementFromPointExample(ByVal dte As DTE2)  

    ' Before running this example, open a code document from a project  
    ' and place the insertion point anywhere inside the source code.  
    Dim sel As TextSelection = _  
        CType(dte.ActiveDocument.Selection, TextSelection)  
    Dim pnt As TextPoint = CType(sel.ActivePoint, TextPoint)  

    ' Discover every code element containing the insertion point.  
    Dim fcm As FileCodeModel = _  
        dte.ActiveDocument.ProjectItem.FileCodeModel  
    Dim elems As String  
    Dim elem As CodeElement  
    Dim scope As vsCMElement  
    For Each scope In [Enum].GetValues(scope.GetType())  
        Try  
            elem = fcm.CodeElementFromPoint(pnt, scope)  
            elems &= elem.Name & " (" & scope.ToString() & ")" & vbCrLf  
       Catch ex As Exception  
            ‘don’t do anything -  
            ‘this is expected when no code elements are in scope  
       End Try  
    Next  
    MsgBox("The following elements contain the insertion point:" _  
            & vbCrLf & vbCrLf & elems)  
End Sub  
public void CodeElementFromPointExample(DTE2 dte)  
{  
    // Before running this example, open a code document from a project  
    // and place the insertion point anywhere inside the source code.  
    TextSelection sel =   
        (TextSelection)dte.ActiveDocument.Selection;  
    TextPoint pnt = (TextPoint)sel.ActivePoint;  
    // Discover every code element containing the insertion point.  
    FileCodeModel fcm =   
    dte.ActiveDocument.ProjectItem.FileCodeModel;  
    string elems = "";  
    vsCMElement scopes = 0;  
    foreach (vsCMElement scope in Enum.GetValues(scopes.GetType()))  
    {  
        try  
        {  
            CodeElement elem = fcm.CodeElementFromPoint(pnt, scope);  
            elems += elem.Name + " (" + scope.ToString() + ")\n";  
        }  
        catch (COMException ex)  
        {  
            //don’t do anything – this is expected if there is   
            //no code element in the scope  
        }  
    }  
    MessageBox.Show(  
        "The following elements contain the insertion point:\n\n" +   
        elems);  
}  

Hinweise

CodeElementFromPoint Gibt das Code Element zurück, das dem TextPoint auf der Grundlage des angegebenen Bereichs oder der Granularität der Kapselung zugeordnet ist. Wenn kein Code Element des angegebenen Typs den Editor Speicherort enthält, CodeElementFromPoint schlägt fehl.

Gilt für