On Wednesday, 6 June 2018 at 13:28:02 UTC, Arafel wrote:

I know it might not be the most idiomatic D, but as somebody with mostly a Java background (with some C and just a bit of C++) it seems something really straightforward to me: myObject.getClass().getFields() [2].

Also, I know I could add some UDA or even crawl the modules and have this information generated automatically at compilation time and added to the type itself in a member, and I might even end up doing it, but honestly, I think it's something that the language should provide in a kind of easy / accessible way.

Powerful as compile-time introspection is, I think runtime shouldn't be forgotten either :-)

Thanks,

A.

[1]: https://dlang.org/library/object/type_info__class.html
[2]: https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getFields--

There is a library that creates reflection metadata for you. [1]

It seems a bit outdated and has some not-that-obvious compilation errors(for example getting ctor and callling it with runtime known type, or some other non template stuff), but other than that seems to be working (note that I didn't thorougly tested it, but its unittests succeeds on DMD 2.080 for both Windows x86 mscoff & x64 )

[1] https://code.dlang.org/packages/witchcraft

Reply via email to