2

It would be very helpful if visual studio 2015/VB.net snippets are capable of getting the function name they're written in. For example a function like so:

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

If it's possible or not, any information would be very helpful (this is a tricky one to google!) thanks in advance.

PS - I'm aware of how to create snippets, but I don't know any syntax that can do the above.

1 Answer 1

4

You can do this using reflection.

Add this to the top of your file:

Imports System.Reflection.MethodBase

Then you can use the following Functions:

GetCurrentMethod().DeclaringType().Name 'Gets the name of the Class/Module

GetCurrentMethod().Name 'Gets the current Sub or Function name

So the following is what you need:

Private Sub aSubRoutine()
    MessageBox.Show(GetCurrentMethod().Name) 'Shows aSubRoutine
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.