April 06, 2014 Does D have reflection? | ||||
---|---|---|---|---|
| ||||
Is there a way to obtain field and method names (as strings) or assign to fields (of structs or classes) if the string is a name which is only known at runtime? For instance, could I write a generic function to reconstruct any object of any type from a JSON object? |
April 06, 2014 Re: Does D have reflection? | ||||
---|---|---|---|---|
| ||||
Posted in reply to dnspies | On Sunday, 6 April 2014 at 02:25:32 UTC, dnspies wrote: > For instance, could I write a generic function to reconstruct any object of any type from a JSON object? Yes, you can use __traits(allMembers) at compile time to build a runtime function that does the setting. .tupleof can do it too, which is what I used in the fromUrlParam function in my web.d that populates a struct from an associative array of runtime strings: https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/web.d#L2507 |
Copyright © 1999-2021 by the D Language Foundation