How get struct value by member name string ?

bauss jacobbauss at gmail.com
Tue May 30 15:24:21 UTC 2023


On Tuesday, 30 May 2023 at 08:46:43 UTC, John Xu wrote:
>
> How to put above enum as a function parameter? Following code 
> wouldn't work:
>
>     string getTMember(T t, enum string memberName) {
>         return __traits(getMember, t, memberName);
>     }
>
> ...

As simple as this:
```
string getTMember(T t, string memberName)() {
     return __traits(getMember, t, memberName);
}

...

writeln(getTMember!(t, "..."));
```


More information about the Digitalmars-d-learn mailing list