Thread overview | |||||
---|---|---|---|---|---|
|
August 04, 2013 String representation of enum value | ||||
---|---|---|---|---|
| ||||
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 Re: String representation of enum value | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marek Janukowicz | 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 Re: String representation of enum value | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robik | 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 |
Copyright © 1999-2021 by the D Language Foundation