EditPoint2.CodeElement[vsCMElement] Свойство

Определение

Возвращает элемент кода с расположением EditPoint.Gets the code element at the EditPoint location.

public:
 property EnvDTE::CodeElement ^ CodeElement[EnvDTE::vsCMElement] { EnvDTE::CodeElement ^ get(EnvDTE::vsCMElement Scope); };
[System.Runtime.InteropServices.DispId(51)]
[get: System.Runtime.InteropServices.DispId(51)]
public EnvDTE.CodeElement CodeElement[EnvDTE.vsCMElement Scope] { get; }
[<System.Runtime.InteropServices.DispId(51)>]
[<get: System.Runtime.InteropServices.DispId(51)>]
member this.CodeElement(EnvDTE.vsCMElement) : EnvDTE.CodeElement
Public ReadOnly Property CodeElement(Scope As vsCMElement) As CodeElement

Параметры

Scope
vsCMElement

Обязательный.Required. КонстантаvsCMElement, указывающая элемент кода указанного вида, который содержит расположение редактора.A vsCMElement constant indicating the code element with the specified kind that contains the editor location.

Значение свойства

CodeElement

Объект CodeElement.A CodeElement object.

Реализации

Атрибуты

Примеры

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

Комментарии

Если указанный тип элемента кода отсутствует в EditPoint расположении, CodeElement возвращается значение Nothing .If the specified code element type is not at the EditPoint location, then CodeElement returns Nothing. CodeElement является ярлыком для TextPoint.Parent.Parent.ProjectItem.CodeModel.CodeElementFromPoint(TextPoint, <scope>)CodeElement is a shortcut for TextPoint.Parent.Parent.ProjectItem.CodeModel.CodeElementFromPoint(TextPoint, <scope>)

Применяется к