Runtime introspection, or how to get class members at runtime Fin D

Adam D. Ruppe destructionator at gmail.com
Wed Jun 6 13:52:35 UTC 2018


On Wednesday, 6 June 2018 at 13:44:39 UTC, Arafel wrote:
> Why not (genuine question)? There's even myObject.classinfo, 
> and I can only assume that there's some reason why it's there...

It holds just barely enough info for dynamic casting, GC, and 
other language implementation stuff.

(and then Object.factory for some weird reason, which actually 
causes bloat for so little benefit)

> Well, thanks for the quick and succinct answer... I guess the 
> question now would be how realistic it would be to propose such 
> an addition to the language... Has it already been discussed?

It is possible to add it to the runtime library right now 
(there's a thing called rtInfo in there made to hold it, it is 
just null right now), just people fight over even a few bytes of 
added metadata. So if it is added, it would surely be some opt-in 
thing that will require your thing be recompiled anyway.

If you can recompile the library, you can add a parallel extended 
info thing (MyReflectionInfo[TypeInfo] array perhaps, populated 
by a static this() ctor created via compile time reflection) that 
gives what you need.

But if you can't recompile the library, the field names are 
simply not there....


More information about the Digitalmars-d-learn mailing list