public override String GetString(String stringName,
String startingCulture, String neutralResourcesCulture)
{
Debug.Assert(stringName != null);
Debug.Assert(_resourceMap != null); // Should have been initialized by now
ResourceCandidate resourceCandidate = null;
stringName = UriUtility.UriEncode(stringName);
if (startingCulture == null && neutralResourcesCulture == null)
{
#pragma warning disable 618
resourceCandidate = _resourceMap.GetValue(stringName);
#pragma warning restore 618
}
else
{
Debug.Assert(_clonedResourceContext != null); // Should have been initialized by now
Debug.Assert(_clonedResourceContextFallBackList != null); // Should have been initialized by now
Debug.Assert(s_globalResourceContextFallBackList != null); // Should have been initialized by now
Debug.Assert(s_globalResourceContextFallBackList.Length > 0); // Should never be empty
// We need to modify the culture fallback list used by the Modern Resource Manager
// The starting culture has to be looked up first, and neutral resources culture has
// to be looked up last.
string newResourceFallBackList = null;
newResourceFallBackList =
(startingCulture == null ? "" : startingCulture + ";") +
s_globalResourceContextFallBackList + // Our tests do not test this line of code, so be extra careful if you modify or move it.
(neutralResourcesCulture == null ? "" : ";" + neutralResourcesCulture);
lock (_clonedResourceContext)
{
// s_globalResourceContextFallBackList may have changed on another thread by now.
// We cannot prevent that from happening because it may have happened on a native
// thread, and we do not share the same lock mechanisms with native code.
// The worst that can happen is that a string is unexpectedly missing
// or in the wrong language.
if (!String.Equals(newResourceFallBackList, _clonedResourceContextFallBackList, StringComparison.Ordinal))
{
_clonedResourceContext.Languages = StringToReadOnlyList(newResourceFallBackList);
_clonedResourceContextFallBackList = newResourceFallBackList;
}
resourceCandidate = _resourceMap.GetValue(stringName, _clonedResourceContext);
}
}
if (resourceCandidate != null)
return resourceCandidate.ValueAsString;
return null;
}
}