コード例 #1
0
        private static string GetUserPreferredUILangs()
        {
            long   pulNumLanguages     = 0;
            int    pcchLanguagesBuffer = 0;
            string str = "";

            if (!NativeCultureResolver.SetThreadPreferredUILanguages(NativeCultureResolver.MUI_CONSOLE_FILTER, (StringBuilder)null, IntPtr.Zero) || !NativeCultureResolver.GetThreadPreferredUILanguages(NativeCultureResolver.MUI_LANGUAGE_NAME | NativeCultureResolver.MUI_MERGE_SYSTEM_FALLBACK | NativeCultureResolver.MUI_MERGE_USER_FALLBACK, out pulNumLanguages, (byte[])null, out pcchLanguagesBuffer))
            {
                return(str);
            }
            byte[] numArray = new byte[pcchLanguagesBuffer * 2];
            if (!NativeCultureResolver.GetThreadPreferredUILanguages(NativeCultureResolver.MUI_LANGUAGE_NAME | NativeCultureResolver.MUI_MERGE_SYSTEM_FALLBACK | NativeCultureResolver.MUI_MERGE_USER_FALLBACK, out pulNumLanguages, numArray, out pcchLanguagesBuffer))
            {
                return(str);
            }
            try
            {
                return(Encoding.Unicode.GetString(numArray).Trim().ToLowerInvariant());
            }
            catch (ArgumentNullException ex)
            {
            }
            catch (DecoderFallbackException ex)
            {
            }
            return(str);
        }
コード例 #2
0
        private static CultureInfo EmulateDownLevel()
        {
            // GetConsoleFallbackUICulture is not required.
            // This is retained in order not to break existing code.
            ushort      langId = NativeCultureResolver.GetUserDefaultUILanguage();
            CultureInfo ci     = new CultureInfo((int)langId);

            return(ci.GetConsoleFallbackUICulture());
        }
コード例 #3
0
 private static CultureInfo EmulateDownLevel() => new CultureInfo((int)NativeCultureResolver.GetUserDefaultUILanguage()).GetConsoleFallbackUICulture();