Пример #1
0
        /// <summary>
        /// Sets value for specified key.
        /// </summary>
        /// <param name="key">A string specifying the key.</param>
        /// <param name="value">An object specifying the value.</param>
        public void SetValue(string key, object value)
        {
            this.CheckNullKey(key);

            if (XmlConverter.CanConvert(value.GetType()))
            {
                string valueString = XmlConverter.ToString(value);

                lock (this._syncRoot)
                {
                    if (this.ArrayContains(this._configuration.AppSettings.Settings.AllKeys, key))
                    {
                        this._configuration.AppSettings.Settings[key].Value = valueString;
                    }
                    else
                    {
                        this._configuration.AppSettings.Settings.Add(key, valueString);
                    }

                    this._settings.Remove(key);
                }
            }
            else
            {
                lock (this._syncRoot)
                {
                    this._settings.SetValue(key, value);

                    this._configuration.AppSettings.Settings.Remove(key);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Sets value for specified key.
        /// </summary>
        /// <param name="key">A string specifying the key.</param>
        /// <param name="value">An object specifying the value.</param>
        public void SetValue(string key, object value)
        {
            this.CheckNullKey(key);

            this._readerWriterLock.AcquireWriterLock(Timeout.Infinite);

            try
            {
                if (XmlConverter.CanConvert(value.GetType()))
                {
                    string valueString = XmlConverter.ToString(value);

                    if (this.ArrayContains(this._configuration.AppSettings.Settings.AllKeys, key))
                    {
                        this._configuration.AppSettings.Settings[key].Value = valueString;
                    }
                    else
                    {
                        this._configuration.AppSettings.Settings.Add(key, valueString);
                    }

                    this._settings.Remove(key);
                }
                else
                {
                    this._settings.SetValue(key, value);

                    this._configuration.AppSettings.Settings.Remove(key);
                }
            }
            finally
            {
                this._readerWriterLock.ReleaseWriterLock();
            }
        }
Пример #3
0
        /// <summary>
        /// Sets value for specified key.
        /// </summary>
        /// <param name="section">A string specifying the section.</param>
        /// <param name="key">A string specifying the key.</param>
        /// <param name="value">An object specifying the value.</param>
        public void SetValue(string section, string key, object value)
        {
            this.CheckNullValue(section);

            this.CheckNullValue(key);

            lock (this._syncRoot)
            {
                if (!this._sections.ContainsKey(section))
                {
                    this._sections[section] = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                }

                this._sections[section][key] = XmlConverter.ToString(value);
            }
        }
Пример #4
0
        /// <summary>
        /// Sets value for specified key.
        /// </summary>
        /// <param name="section">A string specifying the section.</param>
        /// <param name="key">A string specifying the key.</param>
        /// <param name="value">An object specifying the value.</param>
        public void SetValue(string section, string key, object value)
        {
            this.CheckNullValue(section);

            this.CheckNullValue(key);

            this._readerWriterLock.AcquireWriterLock(Timeout.Infinite);

            try
            {
                if (!this.Sections.ContainsKey(section))
                {
                    this.Sections[section] = new Dictionary <string, string>();
                }

                this.Sections[section][key] = XmlConverter.ToString(value);
            }
            finally
            {
                this._readerWriterLock.ReleaseWriterLock();
            }
        }