.net - VB.Net 片段 - 获取函数或子名称

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

如果 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/

相关文章:

python - a == b 为假,但 id(a) == id(b) 为真?

c# - 将 System.Object 转换为 bool 值

.net - 使用 Microsoft.Office.Interop.Excel 从 Excel 读取文本格式

c# - 接收并发异步请求并一次处理一个请求

c# - 是否可以根据条件设置临界区?

c - 将可变数量的参数传递给 C 函数

vb.net - 如何在安装项目时将文件保存/安装到用户计算机的 C 驱动器中?

c# - 有没有办法在 128KB/64KB 上加快对 MS SQL Server 的远程访问?

c++ - 在 C++ 中准确表示 Visual Basic Decimal 变量的替代方法

java - main 方法调用非静态方法