System.Data.LocaleMapper.LcidToLocaleNameInternal C# (CSharp) Method

LcidToLocaleNameInternal() public static method

public static LcidToLocaleNameInternal ( int lcid ) : string
lcid int
return string
        public static unsafe string LcidToLocaleNameInternal(int lcid)
        {
            char* localeName = stackalloc char[LOCALE_NAME_MAX_LENGTH];
            int length = LCIDToLocaleName(unchecked((uint)lcid), localeName, LOCALE_NAME_MAX_LENGTH, 0);

            if (length != 0)
            {
                return new string(localeName, 0, length - 1);
            }
            else
            {
                // LCIDToLocaleName should not return any other errors if we have sufficient buffer space
                int win32Error = Marshal.GetLastWin32Error();
                Debug.Assert(win32Error == ERROR_INVALID_PARAMETER, $"Unknown error returned by {nameof(LCIDToLocaleName)}: {win32Error}. Lcid: {lcid}");

                throw new CultureNotFoundException(nameof(lcid), lcid.ToString(), message: null);
            }
        }

Usage Example

Example #1
0
        private static Tuple <string, int, Encoding> GetDetailsInternal(int lcid)
        {
            string localeName   = LocaleMapper.LcidToLocaleNameInternal(lcid);
            int    ansiCodePage = LocaleMapper.LocaleNameToAnsiCodePage(localeName);

            return(Tuple.Create(localeName, ansiCodePage, Encoding.GetEncoding(ansiCodePage)));
        }