Vb.net 是否可以获取调用另一个方法的方法的名称?

Vb.net 是否可以获取调用另一个方法的方法的名称?,vb.net,methods,Vb.net,Methods,这就是我所说的: Public Shared Sub Test1() Test2() End Sub Public Shared Sub Test2() MsgBox(Test2.LastMethod) ' Test1 End Sub 我想,如果这是可能的话,System.Reflection会被利用吗 有什么想法吗?查看System.Diagnostics.StackFrame类 StackFrame frame = new StackFrame(1); MethodB

这就是我所说的:

Public Shared Sub Test1()
    Test2()
End Sub

Public Shared Sub Test2()
    MsgBox(Test2.LastMethod) ' Test1
End Sub
我想,如果这是可能的话,
System.Reflection
会被利用吗


有什么想法吗?

查看System.Diagnostics.StackFrame类

 StackFrame frame = new StackFrame(1);
 MethodBase method = frame.GetMethod();
 Console.WriteLine(method.Name);

作为补充说明,您不应该依赖于调用方是谁,也不应该使用它,除非您正在编写调试器或出于日志记录目的。

查看System.Diagnostics.StackFrame类

 StackFrame frame = new StackFrame(1);
 MethodBase method = frame.GetMethod();
 Console.WriteLine(method.Name);
Dim stackFrame As New Diagnostics.StackFrame(1)
stackFrame.GetMethod.Name.toString() & stackFrame.GetMethod.DeclaringType.FullName.tostring()
作为补充说明,您不应该依赖于调用方是谁,也不应该使用它,除非您正在编写调试器或出于日志记录的目的

Dim stackFrame As New Diagnostics.StackFrame(1)
stackFrame.GetMethod.Name.toString() & stackFrame.GetMethod.DeclaringType.FullName.tostring()
应该给你全名


应该给你全名。

这个问题应该有帮助:


小心你怎么做。如果您的方法是JIT内联的,您可能会看到错误的方法。

这个问题应该有帮助:


小心你怎么做。如果您的方法是JIT内联的,您可能会看到错误的方法。

另一个警告:如果该方法是JIT内联的,它将返回错误的方法。另一个警告:如果该方法是JIT内联的,它将返回错误的方法。请参阅此问题:的可能重复请参阅此问题:的可能重复