private unsafe CultureTableRecord(String cultureName, bool useUserOverride)
{
BCLDebug.Assert(cultureName != null, "[CultureTableRecord::ctor] cultureName should be valid.");
int cultureID = 0;
// Special case for invariant name
if (cultureName.Length == 0)
{
useUserOverride = false;
cultureID = CultureInfo.LOCALE_INVARIANT;
}
this.m_bUseUserOverride = useUserOverride;
// We prefer to look up by name (if available)
int iDataItem = -1;
if (cultureName.Length > 0)
{
// Check if this is an alternative sort name.
String defaultTableActualName;
int defaultTableCultureID;
string name = cultureName;
int defaultTableDataItem = CultureTable.Default.GetDataItemFromCultureName(name, out defaultTableCultureID, out defaultTableActualName);
if (defaultTableDataItem >= 0 &&
(CultureInfo.GetSortID(defaultTableCultureID) > 0 || defaultTableCultureID == SPANISH_TRADITIONAL_SORT))
{
String replacmentCultureName;
int nonSortId;
if (defaultTableCultureID == SPANISH_TRADITIONAL_SORT)
nonSortId = SPANISH_INTERNATIONAL_SORT;
else
nonSortId = CultureInfo.GetLangID(defaultTableCultureID);
// This is an alternative sort culture.
if (CultureTable.Default.GetDataItemFromCultureID(nonSortId, out replacmentCultureName) >= 0)
{
// This is the replacement culture name for an alternative sort.
name = ValidateCulturePieceToLower(replacmentCultureName, "cultureName", MAXSIZE_FULLTAGNAME);
}
}
// If the compatibility flag is defined and culture is replacemet culture then we don't
// open the custom culture file. instead we'll try to get framework/OS culture.
if (!Environment.GetCompatibilityFlag(CompatibilityFlag.DisableReplacementCustomCulture) ||
IsCustomCultureId(defaultTableCultureID))
{
// we always try the replacement custom cultures first.
// Before call this function, call ValidateCulturePieceToLower() to verify
// that the name does not contain illegal characters (such as "." or backslash.
m_CultureTable = GetCustomCultureTable(name);
}
if (m_CultureTable != null)
{
//
// [CUSTOM/REPLACEMENT CULTURE (.NET CULTURE/SYNTHETIC CULTURE) FOUND BY NAME]
//
iDataItem = this.m_CultureTable.GetDataItemFromCultureName(name, out this.m_ActualCultureID, out this.m_ActualName);
if (defaultTableDataItem >= 0)
{
// This is a replacment culture (since defaultTableDataItem >= 0), use the default ID/Name from the table.
// For de-DE_phoneb, this will set the the actualCultureID to be 0x10407, instead of the LCID for replacment cutlure 0x0407.
this.m_ActualCultureID = defaultTableCultureID;
this.m_ActualName = defaultTableActualName;
}
}
if (iDataItem < 0 && defaultTableDataItem >= 0)
{
//
// [NON-REPLACEMENT .NET CULTURE FOUND BY NAME]
//
this.m_CultureTable = CultureTable.Default;
this.m_ActualCultureID = defaultTableCultureID;
this.m_ActualName = defaultTableActualName;
iDataItem = defaultTableDataItem;
}
}
// If we couldn't get it by name, try culture ID.
if (iDataItem < 0 && cultureID > 0)
{
if (cultureID == CultureInfo.LOCALE_INVARIANT)
{
// Special case for the Invariant culture.
iDataItem = CultureTable.Default.GetDataItemFromCultureID(cultureID, out this.m_ActualName);
if (iDataItem > 0)
{
m_ActualCultureID = cultureID;
m_CultureTable = CultureTable.Default;
}
}
}
// If we found one, use it and return
if (iDataItem >= 0)
{
// Found it, use it
this.m_pData = (CultureTableData*)(this.m_CultureTable.m_pItemData +
this.m_CultureTable.m_itemSize * iDataItem);
this.m_pPool = this.m_CultureTable.m_pDataPool;
// Use name & ID from the file ('cept spanish traditional, which has to stay the same)
this.m_CultureName = this.SNAME;
this.m_CultureID = (m_ActualCultureID == SPANISH_TRADITIONAL_SORT) ? m_ActualCultureID : this.ILANGUAGE;
return;
}
// Error, if we have a name throw that name
if (cultureName != null)
throw new ArgumentException(
String.Format(
CultureInfo.CurrentCulture,
Environment.GetResourceString("Argument_InvalidCultureName"), cultureName), "name");
// No name, throw the LCID
throw new ArgumentException(
String.Format(
CultureInfo.CurrentCulture,
Environment.GetResourceString("Argument_CultureNotSupported"), cultureID), "culture");
}