On Wednesday, 27 December 2017 at 20:04:29 UTC, Marc wrote:
I'd like to set the members of a class by its name at runtime, I would do something like this:

__traits(getMember, myClass, name) = value;

but since name is only know at runtime, I can't use __traits(). What's a workaround for this?

I think you could write something using a combination of these two things:

https://dlang.org/phobos/std_traits.html#FieldNameTuple
https://dlang.org/phobos/std_traits.html#Fields

or maybe '.tupleof':

https://dlang.org/spec/struct.html#struct_properties



Reply via email to