internal static void ValidateLevels() { if (levelsValidated) { return; } bool level1 = !LocalAppContext.GetCachedSwitchValue(UseLegacyAccessibilityFeaturesSwitchName, ref useLegacyAccessibilityFeatures); bool level2 = !LocalAppContext.GetCachedSwitchValue(UseLegacyAccessibilityFeatures2SwitchName, ref useLegacyAccessibilityFeatures2); // 4.7.2 accessibility improvements are building upon the infrastructure introduced in 4.7.1, // thus the application has to opt-in into 4.7.1 level in order to get the 4.7.2 level of support. if (!level1 && level2) { throw new NotSupportedException(SR.GetString(SR.CombinationOfAccessibilitySwitchesNotSupported)); } // If this code is executed concurrently, in the worst case we'll throw the same exception on each thread. levelsValidated = true; }
internal static void ValidateLevels() { if (levelsValidated) { return; } // Level[N+1] accessibility improvements are building upon the infrastructure introduced in Level[N], // thus the application has to opt-in into Level[N] level in order to get the Level[N+1] level of support. Tuple <string, Action <int> >[] levelNamesAndSetters = { Tuple.Create <string, Action <int> >(UseLegacyAccessibilityFeaturesSwitchName, (switchValue) => useLegacyAccessibilityFeatures = switchValue), Tuple.Create <string, Action <int> >(UseLegacyAccessibilityFeatures2SwitchName, (switchValue) => useLegacyAccessibilityFeatures2 = switchValue), Tuple.Create <string, Action <int> >(UseLegacyAccessibilityFeatures3SwitchName, (switchValue) => useLegacyAccessibilityFeatures3 = switchValue) }; bool higherLevelsAreExpectedToBeDisabled = false; bool invalidSwitchesCombination = false; bool[] levelState = new bool[levelNamesAndSetters.Length]; for (int i = 0; i < levelNamesAndSetters.Length; i++) { string levelName = levelNamesAndSetters[i].Item1; Action <int> setLevelSwitchValue = levelNamesAndSetters[i].Item2; int levelSwitchValue = 0; bool levelIsDisabled = LocalAppContext.GetCachedSwitchValue(levelName, ref levelSwitchValue); if (levelIsDisabled) { higherLevelsAreExpectedToBeDisabled = true; } else if (higherLevelsAreExpectedToBeDisabled) { invalidSwitchesCombination = true; } setLevelSwitchValue(levelSwitchValue); levelState[i] = levelIsDisabled; } if (invalidSwitchesCombination) { #if DEPLOYMENT_NAMESPACE throw new NotSupportedException(System.Deployment.Application.Resources.GetString("CombinationOfAccessibilitySwitchesNotSupported")); #else throw new NotSupportedException(SR.CombinationOfAccessibilitySwitchesNotSupported); #endif } // Get other improvements values bool useLegacyToolTipDisplay = LocalAppContext.GetCachedSwitchValue(UseLegacyToolTipDisplaySwitchName, ref useLegacyToolTipDisplayBehavior); // If new ToolTip display behavior is enabled, Level3 should be enabled if (!useLegacyToolTipDisplay && levelState[2]) { #if DEPLOYMENT_NAMESPACE throw new NotSupportedException(System.Deployment.Application.Resources.GetString("KeyboardToolTipDisplayBehaviorRequiresAccessibilityImprovementsLevel3")); #else throw new NotSupportedException(SR.KeyboardToolTipDisplayBehaviorRequiresAccessibilityImprovementsLevel3); #endif } // If this code is executed concurrently, in the worst case we'll throw the same exception on each thread. levelsValidated = true; }