Question

I have a cache object property that I'd like to set to the current class and method in context's name, in order to do some tracking on what methods/classes are generating the largest frequency of these objects.

I can easily grab the current class' name using the code below, but am struggling to find a similar method for gathering the current method's name from the documentation.

set obj.ClassName  = ..%ClassName(1)  //Grab class name
set obj.MethodName =                  //Need to grab the method's name here

I know this can be easily accomplished when the method in question is setup as an object generator, but I'd rather not go down this route.. There has to be a simple way to reference the method's name, right?

///I'd rather not do this to my methods if I don't have to.
Method MyMethod() [ CodeMode = objectgenerator ]
Was it helpful?

Solution

There is a macro to do this: $$$CurrentMethod, defined within %occIO.inc, which you will find in %SYS so you don't need an include to use it. $$$CurrentClass is also defined there.

OTHER TIPS

There is no "official" way to do that in a method.

You can use the $stack($stack,"PLACE") expression to determine currently executed code position. It should be enough for debugging purposes. You may extract a method name from it if you really need. I wouldn't advise to use this in a production code though =)

For things like this I like to use the %Projection classes. You can look up the documentation on how to do it, but the basic idea is that when you compile one class it can be set up to generate another.

If you want to extend what Intersystem's gives you with things like knowing what method you're in (Intersystem's itself just cheats and changes the class compiler without creating a general method everyone can use) you can do some kind of hack like having a #CurrentMethod class parameter and setting up the projection class to replace that with the actual method name on save.

This is a pain to set up, but once you are doing it you can any additional meta-class kinds of features as needed. I do this for similar purposes as you mentioned, and for generating strongly typed result set objects with some convenience methods.

You can also do the same thing in code called from a Cache Studio add-in. Depending on how you write your add-in you could run your code from a menu item, for example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top