Getting member by name in runtime
Marek Janukowicz
marek at janukowicz.net
Wed Aug 21 01:10:29 PDT 2013
I get a string from HTTP request and I need to process a member of this name
of an object. I would like to use __traits(getMember) for that, but of
course it doesn't work with runtime parameters. So what I ended up with is:
foreach( s; __traits(derivedMembers, typeof(obj))) {
if (s == name) ...
}
Of course this looks suboptimal as I run the loop until I find a member
matching the name. Is there any better way to do this?
--
Marek Janukowicz
More information about the Digitalmars-d-learn
mailing list