digitalmars.D - enum toString()?
- Nick Sabalausky (8/8) Feb 25 2005 In C# it is possible to do something like this (Although I'm sure I have...
- Matthew (4/12) Feb 25 2005 AFAIK, it's not currently supported. I think it's something that would
- Charlie Patterson (10/13) Feb 28 2005 This is something I've wanted for a long time, too. Enums are nice to
the syntax and name of the text output function wrong): enum Shape {Circle, Square}; Shape myShape = Circle; forget) That would display the text "Circle". Is this possible in D? If not, is it something what would require reflection?
Feb 25 2005
AFAIK, it's not currently supported. I think it's something that would be nice to have, but I suspect this is a D 2.x feature, if ever. "Nick Sabalausky" <a a.a> wrote in message news:cvof4j$1te2$1 digitaldaemon.com...have the syntax and name of the text output function wrong): enum Shape {Circle, Square}; Shape myShape = Circle; (I forget) That would display the text "Circle". Is this possible in D? If not, is it something what would require reflection?
Feb 25 2005
"Nick Sabalausky" <a a.a> wrote in message news:cvof4j$1te2$1 digitaldaemon.com...enum Shape {Circle, Square}; Shape myShape = Circle; writeln(myShape.ToString());This is something I've wanted for a long time, too. Enums are nice to self-document a program but also get speed by using simple, small ints. However, when it comes time to debug, it is a pain and error-pront to have to create a ShapeToString(Shape) function for each enum. Likewise, it would be nice to read them in: Shape myShape.FromString( "Circle" ); Then a config file could use the actual enum name and save us from writing the common StringToShape(String) function as well.
Feb 28 2005