[Implemented] Return name of current method

There are rare instances where the name of a method needs to be returned, such as for identifying the source of an error, etc.

Here is a procedure provided my Microsoft for doing just that, and would be a nice feature to include implement in Mercury.

''' <summary>Returns the name of the calling member (currently active routine, property, or event).</summary>
''' <param name="RoutineName">[Optional] Reserved placeholder for the name of the routine, property, or event from which the call originated. DO NOT PROVDIE A VALUE FOR THIS ARGUMENT - the operating system will provide the correct value during execution of the routine.</param>
''' <returns>Returns a string value containing the routine's name.</returns>
''' <remarks>This routine must be called from within the routine, property, or event from which its name is to be obtained. Returns an empty string value in the event of an error.</remarks>
Friend Function GetRoutineName(<System.Runtime.CompilerServices.CallerMemberName> Optional RoutineName As System.String = TextAids.TXT_EMPTY) As System.String
    Try 'Attempt the following block(s) of code...
        Return RoutineName 'Return the name of the referenced routine...
    Catch errRntm As System.Exception 'Trap any unexpected errors...
        RaiseError(False, m_MOD_CRNT, "GetRoutineName()", TextAids.TXT_EMPTY, errRntm.HResult, errRntm.Message, True, ResumeModes.RSM_PERSIST) 'Raise an error...

        Return TextAids.TXT_EMPTY 'Return an error value...
    End Try
End Function

Ignore the call to the RaiseError() routine. That part I included as my error handler.

@mh: I thought this one is available in all element languages? Or am I wrong about that?

Oh, I have no idea. I was waiting for you to release Mercury before I purchase Elements…

1 Like

It is. These functions should help: https://docs.elementscompiler.com/API/SystemFunctions/Current/

You can even use them as a default parameter when declaring an api (such as, a constructor for a custom exceptions class), and when not passed explicitly, the compiler will pass the info matching the call site.

Cool. So, I’ll wait until Mercury is released before making anymore feature suggestions so that I can first see what features it does or does not have. :slight_smile:

1 Like

Don’t let us stop you :smile:
Just ask what you want - even if it is already in VB, the information will help others.

FTR, while things are still in pretty rough shape (about ⅔ of the language front-end parser are done; i.e. a to of things parse and just work, but also some seemingly trivial things will still just fail with obscure error because the parser just doesn’t understand a simple thing yet), ordering Elements now will give you access to the Mercury preview, including the weekly builds we ship, with the compiler getting better every time.

Of course all the back-ends are solid (because, shared with the other 5 languages), so the code that does compile will work for all platforms, more for less (barring language-level bugs) reliably.

That too, yes!