Thread overview
String representation of enum value
Aug 04, 2013
Marek Janukowicz
Aug 04, 2013
Robik
Aug 04, 2013
Marek Janukowicz
August 04, 2013
Given following code:

enum ErrorCode {
  BAD_REQUEST,
  UNKNOWN
}

ErrorCode code;

is there any way to get string representation of code with regard to values defined in enum? I mean - if code == 0, I'd like to get a string "BAD_REQUEST", if it's == 1, I'd like to get string a "UNKNOWN". Of course I'd like to use something more consise and elegant than a switch :)

-- 
Marek Janukowicz
August 04, 2013
On Sunday, 4 August 2013 at 13:57:20 UTC, Marek Janukowicz wrote:
> Given following code:
>
> enum ErrorCode {
>   BAD_REQUEST,
>   UNKNOWN
> }
>
> ErrorCode code;
>
> is there any way to get string representation of code with regard to values
> defined in enum? I mean - if code == 0, I'd like to get a string
> "BAD_REQUEST", if it's == 1, I'd like to get string a "UNKNOWN". Of course
> I'd like to use something more consise and elegant than a switch :)

I think std.conv.to!string is what are you looking for :)

http://dpaste.dzfl.pl/e1c38f8f
August 04, 2013
Robik wrote:
> I think std.conv.to!string is what are you looking for :)
> 
> http://dpaste.dzfl.pl/e1c38f8f

Wow, so simple, thanks

-- 
Marek Janukowicz