Thread overview | |||||
---|---|---|---|---|---|
|
February 26, 2005 enum toString()? | ||||
---|---|---|---|---|
| ||||
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? |
February 26, 2005 Re: enum toString()? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | 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? |
February 28, 2005 Re: enum toString()? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | "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. |
Copyright © 1999-2021 by the D Language Foundation