String representation of enum value

Robik szadows at gmail.com
Sun Aug 4 07:01:55 PDT 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


More information about the Digitalmars-d-learn mailing list