/// <summary>
        /// Sets the value of the additional setting. The setting will be added if it does not already exist.
        /// </summary>
        private static void SetValue(this AnalysisConfig config, string settingId, string value)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (string.IsNullOrWhiteSpace(settingId))
            {
                throw new ArgumentNullException("settingId");
            }

            ConfigSetting setting;
            if (config.TryGetConfigSetting(settingId, out setting))
            {
                setting.Value = value;
            }
            else
            {
                setting = new ConfigSetting()
                {
                    Id = settingId,
                    Value = value
                };
            }

            if (config.AdditionalConfig == null)
            {
                config.AdditionalConfig = new System.Collections.Generic.List<ConfigSetting>();
            }
            config.AdditionalConfig.Add(setting);
        }
Beispiel #2
0
        /// <summary>
        /// Attempts to find and return the config setting with the specified id
        /// </summary>
        /// <returns>True if the setting was found, otherwise false</returns>
        private static bool TryGetConfigSetting(this AnalysisConfig config, string settingId, out ConfigSetting result)
        {
            Debug.Assert(config != null, "Supplied config should not be null");
            Debug.Assert(!string.IsNullOrWhiteSpace(settingId), "Setting id should not be null/empty");

            result = null;

            if (config.AdditionalConfig != null)
            {
                result = config.AdditionalConfig.FirstOrDefault(ar => ConfigSetting.SettingKeyComparer.Equals(settingId, ar.Id));
            }
            return(result != null);
        }
        /// <summary>
        /// Attempts to find and return the config setting with the specified id
        /// </summary>
        /// <returns>True if the setting was found, otherwise false</returns>
        private static bool TryGetConfigSetting(this AnalysisConfig config, string settingId, out ConfigSetting result)
        {
            Debug.Assert(config != null, "Supplied config should not be null");
            Debug.Assert(!string.IsNullOrWhiteSpace(settingId), "Setting id should not be null/empty");

            result = null;

            if (config.AdditionalConfig != null)
            {
                result = config.AdditionalConfig.FirstOrDefault(ar => ConfigSetting.SettingKeyComparer.Equals(settingId, ar.Id));
            }
            return result != null;
        }