2016-07-29 26 views
1

如果Visual Studio的2015/VB.net片段能夠得到他們寫的函數名,這將是非常有益的 例如函數像這樣: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 - 我知道如何創建片段,但我不知道任何可以做到上述的語法。

回答

3

你可以使用反射來做到這一點。

添加到您的文件的頂部:

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 
+0

優秀- 非常感謝! –