Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call TypeConverter.ConvertTo or ConvertToString with InvariantCulture but without implementing ITypeDescriptorContext

In my convert method i get the wrong number separators when i use TypeConverter.ConvertToString(Object) because my system is in german. There is another overload for this method which looks like this: TypeConverter.ConvertToString(ITypeDescriptorContext, CultureInfo, Object).

Is there a smart way to obtain the ITypeDescriptorContext or another option to call this method with InvariantCulture besides switching the culture before and after?

like image 299
thalm Avatar asked Jul 11 '13 15:07

thalm


1 Answers

You can pass null as a parameter

TypeConverter.ConvertToString(null, 
                              CultureInfo.InvariantCulture, Object);
like image 107
keyboardP Avatar answered Sep 19 '22 05:09

keyboardP