如果 Visual Studio 2015/VB.net 片段能够获取它们所写入的函数名称,那将非常有帮助。 例如像这样的函数:
private function SomeFunctionA() as Boolean
<insert snippet here and it generates 'SomeText - SomeFunctionA>
end function
private sub aSubRoutine()
<insert snippet here and it generates 'SomeText - aSubRoutine>
end sub
无论是否可能,任何信息都会非常有帮助(这对谷歌来说是一个棘手的信息!)提前致谢。
PS - 我知道如何创建片段,但我不知道任何可以执行上述操作的语法。
最佳答案
您可以使用反射来做到这一点。
将其添加到文件顶部:
Imports System.Reflection.MethodBase
然后您可以使用以下功能:
GetCurrentMethod().DeclaringType().Name 'Gets the name of the Class/Module
GetCurrentMethod().Name 'Gets the current Sub or Function name
所以以下是您所需要的:
Private Sub aSubRoutine()
MessageBox.Show(GetCurrentMethod().Name) 'Shows aSubRoutine
End Sub
关于.net - VB.Net 片段 - 获取函数或子名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38656340/