有没有办法获取Visual Studio中所有函数和Subs文件的列表?我们正在进行大量更改,并且我希望在Excel中有一个列表,以便我可以使用它来跟踪我已经完成的工作。
我还希望得到一个引用这些子/函数的每个函数/子列表,但如果有必要,我可以自己做。
那么,这可以在Visual Studios中完成吗?
答案 0 :(得分:4)
两个选项:
<强> 1。以编程方式使用Reflection和Type.GetMethods
请参阅MSDN页面
以下是该页面上的示例代码(我没有编写此代码,请参阅上面的链接)
Imports System
Imports System.Reflection
Imports System.Reflection.Emit
Imports Microsoft.VisualBasic
' Create a class having two public methods and one protected method.
Public Class MyTypeClass
Public Sub MyMethods()
End Sub 'MyMethods
Public Function MyMethods1() As Integer
Return 3
End Function 'MyMethods1
Protected Function MyMethods2() As [String]
Return "hello"
End Function 'MyMethods2
End Class 'MyTypeClass
Public Class TypeMain
Public Shared Sub Main()
Dim myType As Type = GetType(MyTypeClass)
' Get the public methods.
Dim myArrayMethodInfo As MethodInfo() = myType.GetMethods((BindingFlags.Public Or BindingFlags.Instance Or BindingFlags.DeclaredOnly))
Console.WriteLine((ControlChars.Cr + "The number of public methods is " & myArrayMethodInfo.Length.ToString() & "."))
' Display all the public methods.
DisplayMethodInfo(myArrayMethodInfo)
' Get the nonpublic methods.
Dim myArrayMethodInfo1 As MethodInfo() = myType.GetMethods((BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.DeclaredOnly))
Console.WriteLine((ControlChars.Cr + "The number of protected methods is " & myArrayMethodInfo1.Length.ToString() & "."))
' Display all the nonpublic methods.
DisplayMethodInfo(myArrayMethodInfo1)
End Sub 'Main
Public Shared Sub DisplayMethodInfo(ByVal myArrayMethodInfo() As MethodInfo)
' Display information for all methods.
Dim i As Integer
For i = 0 To myArrayMethodInfo.Length - 1
Dim myMethodInfo As MethodInfo = CType(myArrayMethodInfo(i), MethodInfo)
Console.WriteLine((ControlChars.Cr + "The name of the method is " & myMethodInfo.Name & "."))
Next i
End Sub 'DisplayMethodInfo
End Class 'TypeMain
<强> 2。使用Visual Studio IDE和代码度量标准
可能是一个更容易的选择。