public static int LocaleNameToAnsiCodePage(string localeName)
{
uint ansiCodePage;
if (GetLocaleInfoEx(localeName, LOCALE_RETURN_NUMBER | LOCALE_IDEFAULTANSICODEPAGE, out ansiCodePage, sizeof(uint)) != 0)
{
return unchecked((int)ansiCodePage);
}
else
{
// GetLocaleInfoEx 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(GetLocaleInfoEx)}: {win32Error}. LocaleName: {localeName}");
throw new CultureNotFoundException(nameof(localeName), localeName, message: null);
}
}