コード例 #1
0
        static LocalAppContext()
        {
            // Populate the default values of the local app context
            AppContextDefaultValues.PopulateDefaultValues();

            // Cache the value of the switch that help with testing
            DisableCaching = IsSwitchEnabled(@"TestSwitch.LocalAppContext.DisableCaching");
        }
コード例 #2
0
        public static bool TryGetSwitchOverride(string switchName, out bool overrideValue)
        {
            overrideValue = false;
            bool overrideFound = false;

            AppContextDefaultValues.TryGetSwitchOverridePartial(switchName, ref overrideFound, ref overrideValue);
            return(overrideFound);
        }
コード例 #3
0
        // Token: 0x06000256 RID: 598 RVA: 0x00005EB0 File Offset: 0x000040B0
        public static void PopulateDefaultValues()
        {
            string platformIdentifier;
            string profile;
            int    version;

            AppContextDefaultValues.ParseTargetFrameworkName(out platformIdentifier, out profile, out version);
            AppContextDefaultValues.PopulateDefaultValuesPartial(platformIdentifier, profile, version);
        }
コード例 #4
0
ファイル: AppContext.cs プロジェクト: xied75/coreclr
        static AppContext()
        {
            // Unloading event must happen before ProcessExit event
            AppDomain.CurrentDomain.ProcessExit += OnUnloading;
            AppDomain.CurrentDomain.ProcessExit += OnProcessExit;

            // populate the AppContext with the default set of values
            AppContextDefaultValues.PopulateDefaultValues();
        }
コード例 #5
0
 private static void ParseTargetFrameworkName(out string identifier, out string profile, out int version)
 {
     if (AppContextDefaultValues.TryParseFrameworkName(AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName, out identifier, out version, out profile))
     {
         return;
     }
     identifier = ".NETFramework";
     version    = 40000;
     profile    = string.Empty;
 }
コード例 #6
0
ファイル: LocalAppContext.cs プロジェクト: dox0/DotNet471RS3
        static LocalAppContext()
        {
            // Try to setup the callback into the central AppContext
            s_canForwardCalls = SetupDelegate();

            // Populate the default values of the local app context
            AppContextDefaultValues.PopulateDefaultValues();

            // Cache the value of the switch that help with testing
            DisableCaching = IsSwitchEnabled(@"TestSwitch.LocalAppContext.DisableCaching");
        }
コード例 #7
0
        /// <summary>Tries to get the value of a switch. </summary>
        /// <param name="switchName">The name of the switch. </param>
        /// <param name="isEnabled">When this method returns, contains the value of <paramref name="switchName" /> if <paramref name="switchName" /> was found, or <see langword="false" /> if <paramref name="switchName" /> was not found. This parameter is passed uninitialized. </param>
        /// <returns>
        ///     <see langword="true" /> if <paramref name="switchName" /> was set and the <paramref name="isEnabled" /> argument contains the value of the switch; otherwise, <see langword="false" />. </returns>
        /// <exception cref="T:System.ArgumentNullException">
        ///         <paramref name="switchName" /> is <see langword="null" />. </exception>
        /// <exception cref="T:System.ArgumentException">
        ///         <paramref name="switchName" /> is <see cref="F:System.String.Empty" />. </exception>
        // Token: 0x06000205 RID: 517 RVA: 0x00005304 File Offset: 0x00003504
        public static bool TryGetSwitch(string switchName, out bool isEnabled)
        {
            if (switchName == null)
            {
                throw new ArgumentNullException("switchName");
            }
            if (switchName.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "switchName");
            }
            if (!AppContext.s_defaultsInitialized)
            {
                AppContext.InitializeDefaultSwitchValues();
            }
            isEnabled = false;
            Dictionary <string, AppContext.SwitchValueState> obj = AppContext.s_switchMap;

            lock (obj)
            {
                AppContext.SwitchValueState switchValueState;
                if (AppContext.s_switchMap.TryGetValue(switchName, out switchValueState))
                {
                    if (switchValueState == AppContext.SwitchValueState.UnknownValue)
                    {
                        isEnabled = false;
                        return(false);
                    }
                    isEnabled = ((switchValueState & AppContext.SwitchValueState.HasTrueValue) == AppContext.SwitchValueState.HasTrueValue);
                    if ((switchValueState & AppContext.SwitchValueState.HasLookedForOverride) == AppContext.SwitchValueState.HasLookedForOverride)
                    {
                        return(true);
                    }
                    bool flag2;
                    if (AppContextDefaultValues.TryGetSwitchOverride(switchName, out flag2))
                    {
                        isEnabled = flag2;
                    }
                    AppContext.s_switchMap[switchName] = ((isEnabled ? AppContext.SwitchValueState.HasTrueValue : AppContext.SwitchValueState.HasFalseValue) | AppContext.SwitchValueState.HasLookedForOverride);
                    return(true);
                }
                else
                {
                    bool flag3;
                    if (AppContextDefaultValues.TryGetSwitchOverride(switchName, out flag3))
                    {
                        isEnabled = flag3;
                        AppContext.s_switchMap[switchName] = ((isEnabled ? AppContext.SwitchValueState.HasTrueValue : AppContext.SwitchValueState.HasFalseValue) | AppContext.SwitchValueState.HasLookedForOverride);
                        return(true);
                    }
                    AppContext.s_switchMap[switchName] = AppContext.SwitchValueState.UnknownValue;
                }
            }
            return(false);
        }
コード例 #8
0
        // Token: 0x06000204 RID: 516 RVA: 0x000052B4 File Offset: 0x000034B4
        private static void InitializeDefaultSwitchValues()
        {
            Dictionary <string, AppContext.SwitchValueState> obj = AppContext.s_switchMap;

            lock (obj)
            {
                if (!AppContext.s_defaultsInitialized)
                {
                    AppContextDefaultValues.PopulateDefaultValues();
                    AppContext.s_defaultsInitialized = true;
                }
            }
        }
コード例 #9
0
ファイル: AppContext.cs プロジェクト: dox0/DotNet471RS3
 private static void InitializeDefaultSwitchValues()
 {
     // To save a method call into this method, we are first checking
     // the value of s_defaultsInitialized in the caller.
     lock (s_switchMap)
     {
         if (s_defaultsInitialized == false)
         {
             // populate the AppContext with the default set of values
             AppContextDefaultValues.PopulateDefaultValues();
             s_defaultsInitialized = true;
         }
     }
 }
コード例 #10
0
 private static void PopulateDefaultValuesPartial(string platformIdentifier, string profile, int version)
 {
     if (!(platformIdentifier == ".NETCore") && !(platformIdentifier == ".NETFramework"))
     {
         if ((platformIdentifier == "WindowsPhone" || platformIdentifier == "WindowsPhoneApp") && version <= 80100)
         {
             AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchNoAsyncCurrentCulture, true);
             AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchThrowExceptionIfDisposedCancellationTokenSource, true);
         }
     }
     else if (version <= 40502)
     {
         AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchNoAsyncCurrentCulture, true);
         AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchThrowExceptionIfDisposedCancellationTokenSource, true);
     }
     AppContextDefaultValues.PopulateOverrideValuesPartial();
 }
コード例 #11
0
 // Token: 0x0600020E RID: 526 RVA: 0x000056CC File Offset: 0x000038CC
 private static void PopulateDefaultValuesPartial(string platformIdentifier, string profile, int version)
 {
     if (!(platformIdentifier == ".NETCore") && !(platformIdentifier == ".NETFramework"))
     {
         if (platformIdentifier == "WindowsPhone" || platformIdentifier == "WindowsPhoneApp")
         {
             if (version <= 80100)
             {
                 AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchNoAsyncCurrentCulture, true);
                 AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchThrowExceptionIfDisposedCancellationTokenSource, true);
                 AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchUseLegacyPathHandling, true);
                 AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchBlockLongPaths, true);
                 AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchDoNotAddrOfCspParentWindowHandle, true);
                 AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchIgnorePortablePDBsInStackTraces, true);
             }
         }
     }
     else
     {
         if (version <= 40502)
         {
             AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchNoAsyncCurrentCulture, true);
             AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchThrowExceptionIfDisposedCancellationTokenSource, true);
         }
         if (version <= 40601)
         {
             AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchUseLegacyPathHandling, true);
             AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchBlockLongPaths, true);
             AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchSetActorAsReferenceWhenCopyingClaimsIdentity, true);
         }
         if (version <= 40602)
         {
             AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchDoNotAddrOfCspParentWindowHandle, true);
         }
         if (version <= 40701)
         {
             AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchIgnorePortablePDBsInStackTraces, true);
         }
         if (version <= 40702)
         {
             AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchCryptographyUseLegacyFipsThrow, true);
             AppContext.DefineSwitchDefault(AppContextDefaultValues.SwitchDoNotMarshalOutByrefSafeArrayOnInvoke, true);
         }
     }
     AppContextDefaultValues.PopulateOverrideValuesPartial();
 }
コード例 #12
0
 /// <summary>Trues 来获取一个开关的值。</summary>
 /// <returns>true如果<paramref name="switchName" />设置和<paramref name="isEnabled" />参数中包含的开关 ; 值否则为false。</returns>
 /// <param name="switchName">开关的名称。</param>
 /// <param name="isEnabled">此方法返回时,包含值的<paramref name="switchName" />如果<paramref name="switchName" />找,或false如果<paramref name="switchName" />找不到。此参数未经初始化即被传递。</param>
 /// <exception cref="T:System.ArgumentNullException">
 /// <paramref name="switchName" /> 为 null。</exception>
 /// <exception cref="T:System.ArgumentException">
 /// <paramref name="switchName" /> 为 <see cref="F:System.String.Empty" />。</exception>
 public static bool TryGetSwitch(string switchName, out bool isEnabled)
 {
     if (switchName == null)
     {
         throw new ArgumentNullException("switchName");
     }
     if (switchName.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "switchName");
     }
     isEnabled = false;
     lock (AppContext.s_switchMap)
     {
         AppContext.SwitchValueState local_0;
         if (AppContext.s_switchMap.TryGetValue(switchName, out local_0))
         {
             if (local_0 == AppContext.SwitchValueState.UnknownValue)
             {
                 isEnabled = false;
                 return(false);
             }
             isEnabled = (local_0 & AppContext.SwitchValueState.HasTrueValue) == AppContext.SwitchValueState.HasTrueValue;
             if ((local_0 & AppContext.SwitchValueState.HasLookedForOverride) == AppContext.SwitchValueState.HasLookedForOverride)
             {
                 return(true);
             }
             bool local_3;
             if (AppContextDefaultValues.TryGetSwitchOverride(switchName, out local_3))
             {
                 isEnabled = local_3;
             }
             AppContext.s_switchMap[switchName] = (AppContext.SwitchValueState)((isEnabled ? 2 : 1) | 4);
             return(true);
         }
         bool local_5;
         if (AppContextDefaultValues.TryGetSwitchOverride(switchName, out local_5))
         {
             isEnabled = local_5;
             AppContext.s_switchMap[switchName] = (AppContext.SwitchValueState)((isEnabled ? 2 : 1) | 4);
             return(true);
         }
         AppContext.s_switchMap[switchName] = AppContext.SwitchValueState.UnknownValue;
     }
     return(false);
 }
コード例 #13
0
        private static void TryGetSwitchOverridePartial(string switchName, ref bool overrideFound, ref bool overrideValue)
        {
            string text = null;

            overrideFound = false;
            if (!AppContextDefaultValues.s_errorReadingRegistry)
            {
                text = AppContextDefaultValues.GetSwitchValueFromRegistry(switchName);
            }
            if (text == null)
            {
                text = CompatibilitySwitch.GetValue(switchName);
            }
            bool flag;

            if (text != null && bool.TryParse(text, out flag))
            {
                overrideValue = flag;
                overrideFound = true;
            }
        }
コード例 #14
0
ファイル: AppContext.cs プロジェクト: xied75/coreclr
        /// <summary>
        /// Try to get the value of the switch.
        /// </summary>
        /// <param name="switchName">The name of the switch</param>
        /// <param name="isEnabled">A variable where to place the value of the switch</param>
        /// <returns>A return value of true represents that the switch was set and <paramref name="isEnabled"/> contains the value of the switch</returns>
        public static bool TryGetSwitch(string switchName, out bool isEnabled)
        {
            if (switchName == null)
            {
                throw new ArgumentNullException(nameof(switchName));
            }
            if (switchName.Length == 0)
            {
                throw new ArgumentException(SR.Argument_EmptyName, nameof(switchName));
            }

            // By default, the switch is not enabled.
            isEnabled = false;

            SwitchValueState switchValue;

            lock (s_switchMap)
            {
                if (s_switchMap.TryGetValue(switchName, out switchValue))
                {
                    // The value is in the dictionary.
                    // There are 3 cases here:
                    // 1. The value of the switch is 'unknown'. This means that the switch name is not known to the system (either via defaults or checking overrides).
                    //    Example: This is the case when, during a servicing event, a switch is added to System.Xml which ships before mscorlib. The value of the switch
                    //             Will be unknown to mscorlib.dll and we want to prevent checking the overrides every time we check this switch
                    // 2. The switch has a valid value AND we have read the overrides for it
                    //    Example: TryGetSwitch is called for a switch set via SetSwitch
                    // 3. The switch has the default value and we need to check for overrides
                    //    Example: TryGetSwitch is called for the first time for a switch that has a default value

                    // 1. The value is unknown
                    if (switchValue == SwitchValueState.UnknownValue)
                    {
                        isEnabled = false;
                        return(false);
                    }

                    // We get the value of isEnabled from the value that we stored in the dictionary
                    isEnabled = (switchValue & SwitchValueState.HasTrueValue) == SwitchValueState.HasTrueValue;

                    // 2. The switch has a valid value AND we have checked for overrides
                    if ((switchValue & SwitchValueState.HasLookedForOverride) == SwitchValueState.HasLookedForOverride)
                    {
                        return(true);
                    }

                    // 3. The switch has a valid value, but we need to check for overrides.
                    // Regardless of whether or not the switch has an override, we need to update the value to reflect
                    // the fact that we checked for overrides.
                    bool overrideValue;
                    if (AppContextDefaultValues.TryGetSwitchOverride(switchName, out overrideValue))
                    {
                        // we found an override!
                        isEnabled = overrideValue;
                    }

                    // Update the switch in the dictionary to mark it as 'checked for override'
                    s_switchMap[switchName] = (isEnabled ? SwitchValueState.HasTrueValue : SwitchValueState.HasFalseValue)
                                              | SwitchValueState.HasLookedForOverride;

                    return(true);
                }
                else
                {
                    // The value is NOT in the dictionary
                    // In this case we need to see if we have an override defined for the value.
                    // There are 2 cases:
                    // 1. The value has an override specified. In this case we need to add the value to the dictionary
                    //    and mark it as checked for overrides
                    //    Example: In a servicing event, System.Xml introduces a switch and an override is specified.
                    //             The value is not found in mscorlib (as System.Xml ships independent of mscorlib)
                    // 2. The value does not have an override specified
                    //    In this case, we want to capture the fact that we looked for a value and found nothing by adding
                    //    an entry in the dictionary with the 'sentinel' value of 'SwitchValueState.UnknownValue'.
                    //    Example: This will prevent us from trying to find overrides for values that we don't have in the dictionary

                    // 1. The value has an override specified.
                    bool overrideValue;
                    if (AppContextDefaultValues.TryGetSwitchOverride(switchName, out overrideValue))
                    {
                        isEnabled = overrideValue;

                        // Update the switch in the dictionary to mark it as 'checked for override'
                        s_switchMap[switchName] = (isEnabled ? SwitchValueState.HasTrueValue : SwitchValueState.HasFalseValue)
                                                  | SwitchValueState.HasLookedForOverride;

                        return(true);
                    }

                    // 2. The value does not have an override.
                    s_switchMap[switchName] = SwitchValueState.UnknownValue;
                }
            }
            return(false); // we did not find a value for the switch
        }
コード例 #15
0
 static AppContext()
 {
     // populate the AppContext with the default set of values
     AppContextDefaultValues.PopulateDefaultValues();
 }
コード例 #16
0
 static AppContext()
 {
     AppContextDefaultValues.PopulateDefaultValues();
 }
コード例 #17
0
 // Token: 0x0600025C RID: 604 RVA: 0x0000611D File Offset: 0x0000431D
 static LocalAppContext()
 {
     LocalAppContext.s_canForwardCalls = LocalAppContext.SetupDelegate();
     AppContextDefaultValues.PopulateDefaultValues();
     LocalAppContext.DisableCaching = LocalAppContext.IsSwitchEnabled("TestSwitch.LocalAppContext.DisableCaching");
 }