gpt4 book ai didi

vb.net - 获取类文件中的函数和子列表

转载 作者:行者123 更新时间:2023-12-02 20:42:42 27 4
gpt4 key购买 nike

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

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

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

最佳答案

两种选择:

<强>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

<强>2。使用 Visual Studio IDE 和代码指标

  1. 右键单击项目
  2. 计算代码指标
  3. 在代码指标结果面板中
  4. 右键单击类(class)
  5. 在 Microsoft Excel 中打开所选内容

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

关于vb.net - 获取类文件中的函数和子列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45600419/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com