On Tuesday, 3 May 2022 at 09:52:56 UTC, cc wrote:
On Tuesday, 3 May 2022 at 09:42:45 UTC, cc wrote:
Given a runtime typeid, how can I get the equivalent
fullyQualifiedName without attempting to mangle the string
myself manually? e.g. something I can pass to
`Object.factory`.
Actually, looking at this further, does Object.factory even
support templates? I'm getting null returned from any attempt
to instantiate a templated classname.
It does not.
Object.factory calls TypeInfo_Class.find which just loops through
ModuleInfo and then looks if any of the entries in localClasses
has a name that matches.
So for your example it does this check:
```
if (c.name == "test.Foo!(true)") {
return c; // c is the TypeInfo_Class that matches the given
class name
}
```
https://github.com/dlang/druntime/blob/master/src/object.d#L1661
Afterwards it calls the create function on the TypeInfo_Class
which of course isn't "generic" by any means.
This is where compile-time has its limits compared to runtime
type creation, because templates only live during compile-time
then it isn't really that easy to do something like this, where
it would be trivial in other languages like C#.