Exemple #1
0
        public string ApplyPolicy(string assemblyName)
        {
            ArgumentException.ThrowIfNullOrEmpty(assemblyName);
            if (assemblyName[0] == '\0')
            {
                throw new ArgumentException(SR.Argument_EmptyString, nameof(assemblyName));
            }

            return(assemblyName);
        }
Exemple #2
0
        public ApplicationId(byte[] publicKeyToken, string name, Version version, string?processorArchitecture, string?culture)
        {
            ArgumentException.ThrowIfNullOrEmpty(name);
            ArgumentNullException.ThrowIfNull(version);
            ArgumentNullException.ThrowIfNull(publicKeyToken);

            _publicKeyToken       = (byte[])publicKeyToken.Clone();
            Name                  = name;
            Version               = version;
            ProcessorArchitecture = processorArchitecture;
            Culture               = culture;
        }
Exemple #3
0
        /// <summary>
        /// Assign a switch a value
        /// </summary>
        /// <param name="switchName">The name of the switch</param>
        /// <param name="isEnabled">The value to assign</param>
        public static void SetSwitch(string switchName, bool isEnabled)
        {
            ArgumentException.ThrowIfNullOrEmpty(switchName);

            if (s_switches == null)
            {
                // Compatibility switches are rarely used. Initialize the Dictionary lazily
                Interlocked.CompareExchange(ref s_switches, new Dictionary <string, bool>(), null);
            }

            lock (s_switches)
            {
                s_switches[switchName] = isEnabled;
            }
        }
Exemple #4
0
        /// <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)
        {
            ArgumentException.ThrowIfNullOrEmpty(switchName);

            if (s_switches != null)
            {
                lock (s_switches)
                {
                    if (s_switches.TryGetValue(switchName, out isEnabled))
                    {
                        return(true);
                    }
                }
            }

            if (GetData(switchName) is string value && bool.TryParse(value, out isEnabled))
            {
                return(true);
            }

            isEnabled = false;
            return(false);
        }