[NonSerialized]internal CultureData m_cultureData;
[NonSerialized]internal bool m_isInherited;
-#if FEATURE_LEAK_CULTURE_INFO
- [NonSerialized]private bool m_isSafeCrossDomain;
- [NonSerialized]private int m_createdDomainID;
-#endif // !FEATURE_LEAK_CULTURE_INFO
[NonSerialized]private CultureInfo m_consoleFallbackCulture;
// Names are confusing. Here are 3 names we have:
}
#endregion Serialization
-#if FEATURE_LEAK_CULTURE_INFO
- // Is it safe to send this CultureInfo as an instance member of a Thread cross AppDomain boundaries?
- // For Silverlight, the answer is always no.
- internal bool IsSafeCrossDomain {
- get {
- Debug.Assert(m_createdDomainID != 0, "[CultureInfo.IsSafeCrossDomain] m_createdDomainID != 0");
- return m_isSafeCrossDomain;
- }
- }
-
- internal int CreatedDomainID {
- get {
- Debug.Assert(m_createdDomainID != 0, "[CultureInfo.CreatedDomain] m_createdDomainID != 0");
- return m_createdDomainID;
- }
- }
-
- internal void StartCrossDomainTracking() {
-
- // If we have decided about cross domain safety of this instance, we are done
- if (m_createdDomainID != 0)
- return;
-
- // If FEATURE_LEAK_CULTURE_INFO isn't enabled, we never want to pass
- // CultureInfo as an instance member of a Thread.
- if (CanSendCrossDomain())
- {
- m_isSafeCrossDomain = true;
- }
-
- // m_createdDomainID has to be assigned last. We use it to signal that we have
- // completed the check.
- System.Threading.Thread.MemoryBarrier();
- m_createdDomainID = Thread.GetDomainID();
- }
-#endif // FEATURE_LEAK_CULTURE_INFO
// Is it safe to pass the CultureInfo cross AppDomain boundaries, not necessarily as an instance
// member of Thread. This is different from IsSafeCrossDomain, which implies passing the CultureInfo
private String m_Name;
private Delegate m_Delegate; // Delegate
-#if FEATURE_LEAK_CULTURE_INFO
- private CultureInfo m_CurrentCulture;
- private CultureInfo m_CurrentUICulture;
-#endif
private Object m_ThreadStartArg;
/*=========================================================================
// Do not move! Order of above fields needs to be preserved for alignment
// with native code
// See code:#threadCultureInfo
-#if !FEATURE_LEAK_CULTURE_INFO
[ThreadStatic]
internal static CultureInfo m_CurrentCulture;
[ThreadStatic]
internal static CultureInfo m_CurrentUICulture;
-#endif
static AsyncLocal<CultureInfo> s_asyncLocalCurrentCulture;
static AsyncLocal<CultureInfo> s_asyncLocalCurrentUICulture;
static void AsyncLocalSetCurrentCulture(AsyncLocalValueChangedArgs<CultureInfo> args)
{
-#if FEATURE_LEAK_CULTURE_INFO
- Thread.CurrentThread.m_CurrentCulture = args.CurrentValue;
-#else
m_CurrentCulture = args.CurrentValue;
-#endif // FEATURE_LEAK_CULTURE_INFO
}
static void AsyncLocalSetCurrentUICulture(AsyncLocalValueChangedArgs<CultureInfo> args)
{
-#if FEATURE_LEAK_CULTURE_INFO
- Thread.CurrentThread.m_CurrentUICulture = args.CurrentValue;
-#else
m_CurrentUICulture = args.CurrentValue;
-#endif // FEATURE_LEAK_CULTURE_INFO
}
// Adding an empty default ctor for annotation purposes
// - thread instance member cultures (CurrentCulture and CurrentUICulture)
// confined within AppDomains
// - changes to these properties don't affect the underlying native thread
- //
- // Ifdef:
- // FEATURE_LEAK_CULTURE_INFO : CultureInfos can leak across AppDomains, not
- // enabled in Silverlight
//
// Implementation notes:
// In Silverlight, culture members thread static (per Thread, per AppDomain).
// now need to special case resource lookup for mscorlib, which transitions to the
// default domain to lookup resources. See Environment.cs for more details.
//
-#if FEATURE_LEAK_CULTURE_INFO
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern private bool nativeGetSafeCulture(Thread t, int appDomainId, bool isUI, ref CultureInfo safeCulture);
-#endif // FEATURE_LEAK_CULTURE_INFO
// As the culture can be customized object then we cannot hold any
// reference to it before we check if it is safe because the app domain
// If you add more pre-conditions to this method, check to see if you also need to
// add them to CultureInfo.DefaultThreadCurrentUICulture.set.
-#if FEATURE_LEAK_CULTURE_INFO
- if (nativeSetThreadUILocale(value.SortName) == false)
- {
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidResourceCultureName", value.Name));
- }
- value.StartCrossDomainTracking();
-#else
if (m_CurrentUICulture == null && m_CurrentCulture == null)
nativeInitCultureAccessors();
-#endif
if (!AppContextSwitches.NoAsyncCurrentCulture)
{
}
}
-#if FEATURE_LEAK_CULTURE_INFO
-#endif
internal CultureInfo GetCurrentUICultureNoAppX() {
Contract.Ensures(Contract.Result<CultureInfo>() != null);
return (appDomainDefaultUICulture != null ? appDomainDefaultUICulture : CultureInfo.UserDefaultUICulture);
}
-#if FEATURE_LEAK_CULTURE_INFO
- CultureInfo culture = null;
-
- if (!nativeGetSafeCulture(this, GetDomainID(), true, ref culture) || culture == null) {
- return CultureInfo.UserDefaultUICulture;
- }
-
- return culture;
-#else
return m_CurrentUICulture;
#endif
-#endif
}
// This returns the exposed context for a given context ID.
-#if FEATURE_LEAK_CULTURE_INFO
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static extern private bool nativeSetThreadUILocale(String locale);
-#endif
// As the culture can be customized object then we cannot hold any
// reference to it before we check if it is safe because the app domain
}
}
-#if FEATURE_LEAK_CULTURE_INFO
-#endif
set {
if (null==value) {
throw new ArgumentNullException(nameof(value));
// If you add more pre-conditions to this method, check to see if you also need to
// add them to CultureInfo.DefaultThreadCurrentCulture.set.
-#if FEATURE_LEAK_CULTURE_INFO
- //If we can't set the nativeThreadLocale, we'll just let it stay
- //at whatever value it had before. This allows people who use
- //just managed code not to be limited by the underlying OS.
- CultureInfo.nativeSetThreadLocale(value.SortName);
- value.StartCrossDomainTracking();
-#else
if (m_CurrentCulture == null && m_CurrentUICulture == null)
nativeInitCultureAccessors();
-#endif
if (!AppContextSwitches.NoAsyncCurrentCulture)
{
}
}
-#if FEATURE_LEAK_CULTURE_INFO
-#endif
private CultureInfo GetCurrentCultureNoAppX() {
#if FEATURE_COREFX_GLOBALIZATION
return (appDomainDefaultCulture != null ? appDomainDefaultCulture : CultureInfo.UserDefaultCulture);
}
-#if FEATURE_LEAK_CULTURE_INFO
- CultureInfo culture = null;
-
- if (!nativeGetSafeCulture(this, GetDomainID(), false, ref culture) || culture == null) {
- return CultureInfo.UserDefaultCulture;
- }
-
- return culture;
-#else
return m_CurrentCulture;
#endif
-#endif
}
-#if !FEATURE_LEAK_CULTURE_INFO
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[SuppressUnmanagedCodeSecurity]
private static extern void nativeInitCultureAccessors();
-#endif
/*======================================================================
** Returns the current domain in which current thread is running.