FileCodeModel2.CodeElementFromPoint メソッド (TextPoint, vsCMElement)

更新 : 2007 年 11 月

ソース ファイルの特定の位置あるにコード要素を返します。

名前空間 :  EnvDTE80
アセンブリ :  EnvDTE80 (EnvDTE80.dll 内)

構文

'宣言
Function CodeElementFromPoint ( _
    Point As TextPoint, _
    Scope As vsCMElement _
) As CodeElement
'使用
Dim instance As FileCodeModel2
Dim Point As TextPoint
Dim Scope As vsCMElement
Dim returnValue As CodeElement

returnValue = instance.CodeElementFromPoint(Point, _
    Scope)
CodeElement CodeElementFromPoint(
    TextPoint Point,
    vsCMElement Scope
)
CodeElement^ CodeElementFromPoint(
    TextPoint^ Point, 
    vsCMElement Scope
)
function CodeElementFromPoint(
    Point : TextPoint, 
    Scope : vsCMElement
) : CodeElement

パラメータ

  • Point
    型 : EnvDTE.TextPoint

    必ず指定します。コード要素が必要なエディタの位置を表す TextPoint オブジェクトです。

  • Scope
    型 : EnvDTE.vsCMElement

    必ず指定します。エディタの位置を含む、指定した種類のコード要素を表す vsCMElement 値です。

戻り値

型 : EnvDTE.CodeElement

CodeElement オブジェクトを返します。

実装

FileCodeModel.CodeElementFromPoint(TextPoint, vsCMElement)

解説

CodeElementFromPoint は、指定したスコープまたはコンテインメントの単位に基づいて、TextPoint に関連付けられたコード要素を返します。エディタの位置が含まれる指定した種類のコード要素がない場合、CodeElementFromPoint は失敗します。

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.
    Try
        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())
            elem = fcm.CodeElementFromPoint(pnt, scope)
            If IsNothing(elem) = False Then
                elems &= elem.Name & " (" & scope.ToString() & ")" & _
                    vbCrLf
            End If
        Next

        MsgBox("The following elements contain the insertion point:" _
            & vbCrLf & vbCrLf & elems)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

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.
    try
    {
        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()))
        {
            CodeElement elem = fcm.CodeElementFromPoint(pnt, scope);

            if (elem != null)
                elems += elem.Name + " (" + scope.ToString() + ")\n";
        }

        MessageBox.Show(
            "The following elements contain the insertion point:\n\n" + 
            elems);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

アクセス許可

  • 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

参照

FileCodeModel2 インターフェイス

FileCodeModel2 メンバ

CodeElementFromPoint オーバーロード

EnvDTE80 名前空間

その他の技術情報

方法 : オートメーション オブジェクト モデルのコード例をコンパイルおよび実行する