Rectangle 27 0

localization C : How to use a Type Converter to localize enums?


var foo = TypeDescriptor.GetConverter(typeof(T));
var mystring = foo.ConvertToString(myObject));

But how do you do the conversion?

MSDN of course has the documentation and some examples of TypeConverter implementation.

Once you inherit from TypeConverter, you should override some of its methods to do what you want. You'd probably want to look at ConvertFrom(), ConvertTo(), and ConvertToString() to start with - that's where you would implement the logic to pull out your localized version of your strings.

To create a TypeConverter, simply create a class that inherits from TypeConverter. Then you use the TypeConverterAttribute to tag your class, so that anytime someone tries a convert operation on your class, your TypeConverter is invoked.

Note
Rectangle 27 0

localization C : How to use a Type Converter to localize enums?


Also, you could combine this with an extension method for enums with a name like ToDisplayString.

Note