CodeElement具有Members属性,它是CodeElement的集合。 CodeElement有一个Kind属性,从中你可以知道我们在讨论什么类型的成员。然后,您可以将每个成员投射到适当的界面并浏览。大多数子类都有一个Type属性,其中包含您正在查找的信息。
我在宏编辑器中键入这一点,在一个模块中:
Public Sub DisplayStuff()
Dim objTextSel As TextSelection
Dim objCodeCls As CodeClass
objTextSel = CType(DTE.ActiveDocument.Selection, TextSelection)
objCodeCls = CType(objTextSel.ActivePoint.CodeElement(vsCMElement.vsCMElementClass), CodeClass)
If objCodeCls Is Nothing Then
MsgBox("Please launch this macro when the cursor is within a class")
Exit Sub
End If
For Each elt As CodeElement2 In objCodeCls.Members
Select Case elt.Kind
Case vsCMElement.vsCMElementVariable
Dim v As CodeVariable2 = CType(elt, CodeVariable2)
MsgBox(v.Name & " is a variable of type " & v.Type.AsString)
Case vsCMElement.vsCMElementProperty
Dim p As CodeProperty2 = CType(elt, CodeProperty2)
MsgBox(p.Name & " is of type " & p.Type.AsString)
End Select
Next
End Sub
,只是需要的类,它是当光标在编辑器中,并显示任何字段或属性的类型信息。