获取类文件中的函数和子列表

DFo*_*k42 2 vb.net visual-studio-2015

有没有办法在 Visual Studios 中获取类文件中所有函数和子项的列表?我们正在进行大量更改,我希望在 excel 中有一个列表,以便我可以使用它来跟踪我已经完成的工作。

我还想获得引用这些子/函数的每个函数/子的列表,但如有必要,我可以自己做。

那么,这可以在 Visual Studios 中完成吗?

djv*_*djv 5

两种选择:

1. 以编程方式使用反射和 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
Run Code Online (Sandbox Code Playgroud)

2. 使用 Visual Studio IDE 和代码指标

  1. 右键单击项目
  2. 计算代码指标
  3. 在代码度量结果窗格中
  4. 右键单击类
  5. 在 Microsoft Excel 中打开选择

可能是一个更简单的选择。