[Mono-dev] [PATCH] implement support for auto:LANGID culture specifications in ASP.NET 2.0 globalization
Raja R Harinath
rharinath at novell.com
Mon Nov 20 07:06:35 EST 2006
Hi,
Marek Habersack <grendel at caudium.net> writes:
> Index: System.Web/HttpApplication.cs
> ===================================================================
> --- System.Web/HttpApplication.cs (revision 68155)
> +++ System.Web/HttpApplication.cs (working copy)
> @@ -95,6 +95,14 @@
> // The factory for the handler currently running.
> //
> IHttpHandlerFactory factory;
> +
> +#if NET_2_0
> + //
> + // Whether the thread culture is to be auto-set
> + //
> + bool autoCulture;
> + bool autoUICulture;
> +#endif
The #if guard isn't necessary. Maybe add a comment that these will
always be false in the 1.1 profile.
> +#if NET_2_0
> + internal CultureInfo GetThreadCulture (HttpRequest request, CultureInfo culture, bool isAuto)
> + {
> + if (!isAuto)
> + return culture;
> + CultureInfo ret = null;
> + string[] languages = request.UserLanguages;
> + try {
> + if (languages != null && languages.Length > 0)
> + ret = new CultureInfo (languages[0]);
> + } catch {
> + }
> +
> + if (ret == null)
> + ret = culture;
> +
> + return ret;
> + }
> +#endif
As well as this. Or, you can put the guard only around the meat of the
code if it doesn't compile ('string [] languages ...' to 'catch {}').
> void PreStart ()
> {
> #if !TARGET_J2EE
> @@ -1009,12 +1039,20 @@
> Thread th = Thread.CurrentThread;
> if (app_culture != null) {
> prev_app_culture = th.CurrentCulture;
> +#if NET_2_0
> + th.CurrentCulture = GetThreadCulture (Request, app_culture, autoCulture);
> +#else
> th.CurrentCulture = app_culture;
> +#endif
> }
>
> if (appui_culture != null) {
> prev_appui_culture = th.CurrentUICulture;
> +#if NET_2_0
> + th.CurrentUICulture = GetThreadCulture (Request, appui_culture, autoUICulture);
> +#else
> th.CurrentUICulture = appui_culture;
> +#endif
> }
And just use the first variant. We don't want unnecessary '#if's
sprinkled around the code since it increases the number of code paths
that need to examined.
- Hari
More information about the Mono-devel-list
mailing list