我正在尝试编写一个visualstudio插件。以下代码用于在visualstudio代码窗口中显示所选文本的全局变量或类名或函数名。但是,它不会显示函数内部定义的变量。如何修改此项以显示局部变量?
'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
微软似乎没有公开底层API。我做了一项研究,却找不到访问函数定义中代码元素的方法。