TextPoint.CodeElement プロパティ

更新 : 2007 年 11 月

TextPoint の位置にあるコード要素を返します。

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

構文

'宣言
ReadOnly Property CodeElement ( _
    Scope As vsCMElement _
) As CodeElement
'使用
Dim instance As TextPoint
Dim Scope As vsCMElement
Dim value As CodeElement

value = instance.CodeElement(Scope)
CodeElement CodeElement[
    vsCMElement Scope
] { get; }
property CodeElement^ CodeElement[[InAttribute] vsCMElement Scope] {
    CodeElement^ get ([InAttribute] vsCMElement Scope);
}
JScript では、インデックス付きプロパティはサポートされません。

パラメータ

  • Scope
    型 : EnvDTE.vsCMElement

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

プロパティ値

型 : EnvDTE.CodeElement

CodeElement オブジェクト。

解説

指定したコード要素の種類が TextPoint の位置にない場合、CodeElement は Nothing を返します。CodeElement は、TextPoint.Parent.Parent.ProjectItem.CodeModel.CodeElementFromPoint(TextPoint, <scope>) のショートカットです。

Sub CodeElementExample(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 elems As String
        Dim elem As CodeElement
        Dim scope As vsCMElement
        For Each scope In [Enum].GetValues(scope.GetType())
            elem = pnt.CodeElement(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 CodeElementExample(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.
        string elems = "";
        vsCMElement scopes = 0;

        foreach (vsCMElement scope in Enum.GetValues(scopes.GetType()))
        {
            CodeElement elem = pnt.get_CodeElement(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);
    }
}

アクセス許可

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

参照

参照

TextPoint インターフェイス

TextPoint メンバ

EnvDTE 名前空間

その他の技術情報

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