String to enum

2010-12-10 Thread useo
Hi, does anyone know how I can cast a string to an enum which also contains strings? For example: enum MyENUM : string { x = "123" y = "456" z = "789" } ... string myString = X; to!(MyENUM)(myString); // Error: cannot implicitly convert expression (_adDupT((& D12TypeInfo_Aya6__initZ),s)) of

Re: String to enum

2010-12-10 Thread Jesse Phillips
useo Wrote: > Hi, > > does anyone know how I can cast a string to an enum which also > contains strings? For example: > > enum MyENUM : string { > > x = "123" > y = "456" > z = "789" > > } > > ... > > string myString = X; > to!(MyENUM)(myString); // Error: cannot implicitly convert > expres

Converting from string to enum by name

2012-05-28 Thread Jarl André
Hi I have a project on github, https://github.com/jarlah/d2-simple-socket-server, where I have added very custom logger library. In this logger library I have an enum LogLevel that looks like enum LogLevel { ALL, INFO, WARNING etc } Questions: 1. Is there a way to convert from string "INFO

Re: Converting from string to enum by name

2012-05-29 Thread Jarl André
On Monday, 28 May 2012 at 18:53:50 UTC, Ali Çehreli wrote: On 05/28/2012 11:50 AM, "Jarl André" " wrote: > 1. Is there a way to convert from string "INFO" to LogLevel.INFO, by name? conv.to can do that: import std.conv; enum LogLevel { ALL, INFO, WARNING } void main() { enum l = to!LogL