Runtime evaluation

nrgyzer nrgyzer at gmail.com
Thu Jul 7 14:23:26 PDT 2011


Hi guys,

I'm trying to read a string from a text file which contains a value of an enumeration like:

enum MyEnum : string {
   Entry_1 = "abc",
   Entry_2 = "def",
   Entry_3 = "ghi",
}

Stream s = new File("myFile.ext", FileMode.In);
uint len;
s.read(len);
string entry = cast(string) s.readString(len);
s.close();

writeln(mixin("MyEnum." ~ entry));

myFile.ext may contain:
...
Entry_2
Entry_1
Entry_2
Entry_3
...

But mixin's are for compile time only... is there any chance to do this or do I've to use another method (like if/else or switch/case):

if (entry == "Entry_1") ...
else if (entry == "Entry_2") ...
...

Thanks a lot!


More information about the Digitalmars-d-learn mailing list