コード例 #1
0
ファイル: Config.cs プロジェクト: kouweizhong/CodePlexDevLib
        /// <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
ファイル: Config.cs プロジェクト: kouweizhong/CodePlexDevLib
        /// <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();
            }
        }