digitalmars.D - enum toString()?
- Nick Sabalausky <a a.a> Feb 25 2005
- "Matthew" <admin stlsoft.dot.dot.dot.dot.org> Feb 25 2005
- "Charlie Patterson" <charliep1 excite.com> Feb 28 2005
In C# it is possible to do something like this (Although I'm sure I have
the syntax and name of the text output function wrong):
enum Shape {Circle, Square};
Shape myShape = Circle;
writeln(myShape.ToString()); // Or whatever C#'s printf-queivilent is (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
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...In C# it is possible to do something like this (Although I'm sure I have the syntax and name of the text output function wrong): enum Shape {Circle, Square}; Shape myShape = Circle; writeln(myShape.ToString()); // Or whatever C#'s printf-queivilent is (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









"Matthew" <admin stlsoft.dot.dot.dot.dot.org> 