[英]Get functions in VS using macros
如何使用VS宏在Visual Studio中獲取代碼文件中的所有功能? 我正在使用Visual Studio 2008。
我還需要獲取功能是私有保護的還是公共的。 現在,我知道我可以自己解析代碼並對其進行檢查,但是我想以一種適當的方式進行編碼,並認為vs宏環境應允許了解有關函數的所有信息。
請參閱HOWTO:從Visual Studio .NET宏或加載項 導航文件 的代碼元素也許如何: 從Visual Studio .NET宏或加載項 導航解決方案的文件對您來說很有趣。
獲取功能可訪問性很容易。 在第一篇文章之后,您將擁有CodeElement對象。 如果類型為CodeFunction,則可以將其強制轉換為CodeFunction(或CodeFunction2)類型。 CodeFunction包含許多屬性,包括所需的Access。 我已經從本文修改了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宏。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.