Class.classinfo.name and Class.stringof
HOSOKAWA Kenchi
hskwk at inter7.jp
Tue May 19 05:22:05 PDT 2009
There are two ways to get class name as string;
Class.classinfo.name and Class.stringof.
I have tried to use class names as string for conditional codes, instead of dynamic casts,
if- and switch-statements, associative arrays, or something.
Then I bumped into a problem.
Class.classinfo.name returns class name with full module names.
On the contrary, Class.stringof returns without module name.
They returns different string for the same class.
This means there is no way to compare class names determined in compile-time and runtime.
A)
Make Class.classinfo to be invariant (leave object.classinfo as runtime at the same time).
Then we are able to get same string for a class in both compile-time and runtime.
I think this might be a better solution.
B)
Append full module names to Class.stringof.
This will cause destructive change.
More information about the Digitalmars-d
mailing list