Setting DateTime.Parse( ) default IFormatProvider

  • Thread starter Thread starter vooose
  • Start date Start date
V

vooose

Consider an application which has *many* references to

DateTime.Parse(string);

Is there a way, say when the application first starts up to force this
method to use a specific IFormatProvider, so every
DateTime.Parse(string) is really

DateTime.Parse(string, format);

(where format is defined once)

Now you might be saying 'thats easy, just go and set your Regional
settings to whatever format you want'. Unfortunatly that is beyond my
control since the application is deployed to many clients. You might
also say, 'find every instance of DateTime.parse(string) and replace
with DateTime.Parse(string, format). I only really want to do that if
forced to because

a) there is many many places i have to do this
b) Other programmers have to remember to do this each time they do a
DateTime.Parse( )

I'm hoping there is something like

System.SetDefaultIFormatProvider(myFormat);
:D

Regards
 
You can do:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-AU");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-AU");

but unfortunately child threads dont inherit this property so not a
solution
 
Back
Top