【问题标题】:VB.Net snippets - get function or sub nameVB.Net 片段 - 获取函数或子名称
【发布时间】:2016-12-04 00:35:42
【问题描述】:

如果 Visual Studio 2015/VB.net sn-ps 能够获取它们写入的函数名称,那将非常有帮助。 例如这样的函数:

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 - 我知道如何创建 sn-ps,但我不知道任何可以执行上述操作的语法。

【问题讨论】:

    标签: .net vb.net methods visual-studio-2015 code-snippets


    【解决方案1】:

    您可以使用反射来做到这一点。

    将此添加到文件顶部:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-18
      • 1970-01-01
      • 2021-07-02
      • 1970-01-01
      • 2023-03-17
      • 2011-09-09
      • 1970-01-01
      相关资源
      最近更新 更多