Globalization & Custom Converters

  • Thread starter Thread starter hufaunder
  • Start date Start date
H

hufaunder

I have some enums that I want to convert to strings so they can be
shown on the GUI (using Framework 3.0). The easiest way is using
ToString() but that does not support multiple languages. I am familiar
with custom converters of class objects but how do I achieve this for
enums. For instance:

enum Vehicle { Car, Motorcycle, Train }

Vehicle myVehicle = Vehicle.Car;
1) String value = (String) myVehicle;
2) String value = Convert.ToString(myVehicle)

Both solution 1) or 2) are fine as long as I can do it in some
'standard' way.

Thanks
 
I haven't tested it, but you might be able to write a custom
TypeConverter, and associate it with the *properties* that use that
enum, rather than the type itself. This should allow you to do your
own locale-based parse/format - and it should theoretically require no
UI coding since almost all data-bound controls correctly use
type-converters from the PropertyDescriptor. Not quite all, though ;-p

Marc
 
Back
Top