Question
· Aug 23

How do I get the instantiated name of a class

Hi Guys

How do get the item name of a class? I have several items derived from the same class, and for error reporting I want to get the name of the item which created it, rather than the class it is derived from from.

e.g. InPhase.LEGACY.GetUpdateNotification, InPhase.LFPSE.GetUpdateNotification and InPhase.ADHOC.GetUpdateNotification are all derived from the same class  InPhase.Services.LoadInPhaseUpdates

I'm aware that the $CLASSNAME($THIS) can be used to get classname, but this doesn't help.

Can anyone help?

Andy

Product version: IRIS 2021.1
$ZV: InPhase.Services.LoadInPhaseUpdates
Discussion (6)2
Log in or sign up to continue

Are you trying to get all of the classes that a class extends? You can do that like this:

	set classname = $CLASSNAME($THIS)
	&sql(select primarysuper into :super from %dictionary.compiledclass where id=:classname)
	w super,!

If you do that, super is a ~ separated list of the class and everything that it inherits from, which is probably actually more information than you need.

Hi,

so just to summarize what i understood. 

You have a superclass with some logging method. Now every time the logging method is called from a child class it logs the name of the superclass instead of the Child class?

If so the issue is that $CLASSNAME returns the name of the class where the method is located not where a method is called from.

To work around this behaviour you would need to rewrite your logging method to be a codegenerator, e.g.

instead of:

ClassMethod Log()
{
    w $CLASSNAME()
}

rewrite it like this:
 

ClassMethod Log() [ codemode = generator, forcegenerate ]
{
    do %code.WriteLine("    w $CLASSNAME()")
    quit 1
}

This will locate the Log method from the superclass to the child class and have $CLASSNAME resolve to the child classname.

You have a superclass with some logging method. Now every time the logging method is called from a child class it logs the name of the superclass instead of the Child class?

No

If so the issue is that $CLASSNAME returns the name of the class where the method is located not where a method is called from.

Wrong, it returns the class name where it is called from.

Your first sample method works just fine, no need for method generator.

I suggest you to make a quick test.