다음을 통해 공유


FileCodeModel2.CodeElementFromPoint 메서드 (TextPoint, vsCMElement)

소스 파일의 특정 위치에 있는 코드 요소를 반환합니다.

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

구문

‘선언
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

매개 변수

  • Point
    형식: EnvDTE.TextPoint
    필수 요소.코드 요소를 제공해야 하는 편집기 위치를 나타내는 TextPoint 개체입니다.
  • Scope
    형식: EnvDTE.vsCMElement
    필수 요소.편집기 위치를 포함하는 지정된 형식의 코드 요소를 나타내는 vsCMElement 값입니다.

반환 값

형식: EnvDTE.CodeElement
CodeElement 개체입니다.

설명

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

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

FileCodeModel2 인터페이스

CodeElementFromPoint 오버로드

EnvDTE80 네임스페이스

기타 리소스

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