Metodo FileCodeModel2.CodeElementFromPoint (TextPoint, vsCMElement)

Restituisce un elemento di codice in un percorso specifico in un file di origine.

Spazio dei nomi:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Sintassi

'Dichiarazione
Function CodeElementFromPoint ( _
    Point As TextPoint, _
    Scope As vsCMElement _
) As CodeElement
CodeElement CodeElementFromPoint(
    TextPoint Point,
    vsCMElement Scope
)
CodeElement^ CodeElementFromPoint(
    TextPoint^ Point, 
    vsCMElement Scope
)
abstract CodeElementFromPoint : 
        Point:TextPoint * 
        Scope:vsCMElement -> CodeElement 
function CodeElementFromPoint(
    Point : TextPoint, 
    Scope : vsCMElement
) : CodeElement

Parametri

  • Point
    Tipo: EnvDTE.TextPoint
    obbligatorio.In TextPoint oggetto che rappresenta la posizione nell'editor per il quale si desidera che un elemento di codice.
  • Scope
    Tipo: EnvDTE.vsCMElement
    obbligatorio.In vsCMElement stimare rappresentare l'elemento di codice di tipo specificato contenente la posizione nell'editor.

Valore restituito

Tipo: EnvDTE.CodeElement
In CodeElement oggetto.

Note

CodeElementFromPoint restituisce l'elemento di codice associato TextPoint sulla base dell'ambito o di granularità specificato di contenimento.Se nessun elemento di codice di tipo specificato contiene la posizione nell'editor, quindi CodeElementFromPoint ha esito negativo.

Esempi

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

Sicurezza di .NET Framework

Vedere anche

Riferimenti

FileCodeModel2 Interfaccia

Overload CodeElementFromPoint

Spazio dei nomi EnvDTE80

Altre risorse

Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione