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
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
I don't understand what you refer with "the name of the item which created it", can you provide an example of what you expect as result?
$CLASSNAME($THIS) returns the actual class name of $this instance, not a superclass or the class where is executed (possibly a superclass).
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.
If you are looking for the class name where a currently-running method originates, you could also try:
set method = $CLASSNAME($THIS)_"||"_$P($Stack($stack,"PLACE"),"+",1) &sql(select Origin into :origin from %Dictionary.CompiledMethod where ID1 = :method) w origin,!
Use %Classname(1) method?
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.
No
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.