见
HOWTO: Navigate the code elements of a file from a Visual Studio .NET macro or add-in
也许
HOWTO: Navigate the files of a solution from a Visual Studio .NET macro or add-in
对你来说很有趣。
获取函数可访问性很容易。在第一篇文章之后,您有了codeelement对象。如果它是codefunction类型,则可以将其强制转换为codefunction(或codefunction2)类型。codeFunction包含许多属性,包括您需要的访问权限。我已经修改了本文中的showcodeelement,因此它只显示函数,还显示它们的可访问性:
Private Sub ShowCodeElement(ByVal objCodeElement As CodeElement)
Dim objCodeNamespace As EnvDTE.CodeNamespace
Dim objCodeType As EnvDTE.CodeType
Dim objCodeFunction As EnvDTE.CodeFunction
If TypeOf objCodeElement Is EnvDTE.CodeNamespace Then
objCodeNamespace = CType(objCodeElement, EnvDTE.CodeNamespace)
ShowCodeElements(objCodeNamespace.Members)
ElseIf TypeOf objCodeElement Is EnvDTE.CodeType Then
objCodeType = CType(objCodeElement, EnvDTE.CodeType)
ShowCodeElements(objCodeType.Members)
ElseIf TypeOf objCodeElement Is EnvDTE.CodeFunction Then
Try
Dim msg As String = objCodeElement.FullName & vbCrLf
Dim cd As EnvDTE.CodeFunction = DirectCast(objCodeElement, CodeFunction)
Select Case cd.Access
Case vsCMAccess.vsCMAccessDefault
msg &= "Not explicitly specified. It is Public in VB and private in C#."
Case Else
msg &= cd.Access.ToString
End Select
MsgBox(msg)
Catch ex As System.Exception
' Ignore
End Try
End If
End Sub
然后更改并执行showfilecodemodel宏。