On Thursday, 23 January 2014 at 15:07:18 UTC, Uplink_Coder wrote:
Hello,
I have an Enum to represent possible Options for a selectList
e.g
enum options {
blueish="Blue",
redish ="Red"
}
and I want the List-Entrys to say
"blueish" or "redish".
the value send to the app should be
"Blue" or "Red".
I can use __traits(allMembers,Enum)
for the identifiers, but how do I get the Values ?
import std.stdio;
enum Options {
blueish="Blue",
redish ="Red"
}
void main() {
foreach(m; __traits(allMembers, Options)) {
writeln(m);
writeln(cast(string)__traits(getMember, Options, m));
}
}
The cast forces it to grab the value. Note where Options values
are of type string. Its the same as explicitly saying enum T :
string {.