从visual studio addin访问本地变量

时间:2012-03-24 17:50:34

标签: vb.net visual-studio-2010 envdte

我正在尝试编写一个visual studio addin。以下代码用于在visual studio代码窗口中显示所选文本的全局变量或类名或函数名。但是它不显示函数内定义的变量。如何修改它以显示局部变量?

'Call this function inside OnConnection event of the addin

Sub displayCodeElementName()

    ' Before running this example, open a code document from a project
    ' and place the insertion point inside a variable definition.
    Try
        ' Retrieve the CodeVariable at the insertion point.
        Dim sel As TextSelection = _
            CType(applicationObject.ActiveDocument.Selection, TextSelection)
        Dim var As CodeVariable2 = CType(sel.ActivePoint.CodeElement(vsCMElement.vsCMElementVariable), CodeVariable2)

        ' Display the code element name

            MsgBox(var.Name & " is the name.")

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End sub

1 个答案:

答案 0 :(得分:0)

似乎Microsoft没有公开底层API。我做了一项研究,无处可寻找一种方法来访问函数定义中的代码元素。