我的意图与此问题相同:
Automatically call all functions matching a certain pattern in python
但我需要VB.NET中的解决方案(如果技术上可行)。这在VB.NET中可能吗?
答案 0 :(得分:4)
当然,你可以做到这一点,这就是反思:
Imports System.Reflection
Module Module1
Sub Main()
Dim methods = GetType(Module1).GetMethods() _
.Where(Function(m) m.Name.StartsWith("Setup"))
For Each method As MethodInfo In methods
method.Invoke(Nothing, Nothing)
Next
End Sub
Sub Setup1()
Console.WriteLine(1)
End Sub
Sub Setup2()
Console.WriteLine(2)
End Sub
Sub Setup3()
Console.WriteLine(3)
End Sub
End Module