Share via


TextPoint.CodeElement 속성

TextPoint 위치에 있는 코드 요소를 반환합니다.

네임스페이스:  EnvDTE
어셈블리:  EnvDTE(EnvDTE.dll)

구문

‘선언
ReadOnly Property CodeElement ( _
    Scope As vsCMElement _
) As CodeElement
CodeElement this[
    vsCMElement Scope
] { get; }
property CodeElement^ CodeElement[[InAttribute] vsCMElement Scope] {
    CodeElement^ get ([InAttribute] vsCMElement Scope);
}
abstract CodeElement : 
        Scope:vsCMElement -> CodeElement with get
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);
    }
}

.NET Framework 보안

참고 항목

참조

TextPoint 인터페이스

EnvDTE 네임스페이스

기타 리소스

방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행