Get symbols (and/or UDAs) of subclass from superclass
james.blachly at gmail.com
Sun Mar 15 20:18:03 UTC 2020
I would like to programmatically retrieve members of a subclass to
create a self-documenting interface. I am afraid that my approach is not
possible due to need for compile time __traits / std.traits, and runtime
typeinfo. My proposed approach is as follows:
// loop over __traits(allMembers, typeof(this)) or
/// There may be a dozen Derived classes
class Derived1 : Base
@Config("a name", "a description")
class Derived2 : Base
@Config("another", "more description")
Unfortunately, I am afraid this doesn't look possible because of the
need for compile-time UDAs and runtime TypeInfo. Is there a way to do
this without re-implementing toString in every single derived class? I
expect there to be many derived classes.
Other ideas welcomed, as I usually write C-style D and am only recently
taking a stab at OO Inheritance features.
Thanks in advance.
More information about the Digitalmars-d-learn