String representation of enumerations

12 01 2008

Click here for the updated version of this post


Actions

Information

2 responses

24 01 2008
dbilli

Ciao Matteo, scusami se leggo solo ora l’articolo ma sono stato parecchio impegnato, infatti ho postato pochissimi articoli anche nel mio blog. Ho letto il tuo articolo, sicuramente è interessante il modo in cui hai usato l’enumerativo. Tuttavia io trovo più comodo l’utilizzo di alcuni metodi nativamente presenti nell’oggetto DateTime che permettono di avere direttamente la data, l’ora o altro nella stringa rappresentativa, tra l’altro supportando automaticamente le diversità di localizzazione (in america con “yyyy/mm/dd” e in italia “dd/mm/yyyy” per intenderci). Buon lavoro comunque.

A presto!

3 11 2010
Silvio

Very nice job imo.
I know this post is _old_ but this is a really clever solution.
Enums in C# are very limited: wrapping them in a custom value object (http://c2.com/cgi/wiki?ValueObject) overcomes the limitations. The added complexity of a new type in the program is very (very) worth the cost because you centralize handling of the enum.
Btw, I would think of a factory method and private ctor for the value object and would not nest its class…
Learned something, thank you very much!

Leave a comment