Thread overview
enum toString()?
Feb 26, 2005
Nick Sabalausky
Feb 26, 2005
Matthew
Feb 28, 2005
Charlie Patterson
February 26, 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?
February 26, 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?


February 28, 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.