Exemplo n.º 1
0
        public void Set <T>(string key, T value)
        {
            var    actKey   = key;
            bool   isNew    = true;
            object oldValue = null;

            if (this.SettingsData.ContainsKey(actKey))
            {
                oldValue = this.SettingsData[actKey];
                if (oldValue != null)
                {
                    isNew = (!oldValue.Equals(value));
                }
                else
                {
                    isNew = (value != null);
                }
            }

            if (isNew)
            {
                var args = new SettingChangeEventArgs(key, oldValue, value);
                this.OnSettingChanging(args);
                this.SettingsData[actKey] = value;
                this.OnSettingChanged(args);
            }
        }
Exemplo n.º 2
0
 private void OnSettingChanged(SettingChangeEventArgs args)
 {
     if (SettingChanged != null)
     {
         SettingChanged(this, args);
     }
 }
Exemplo n.º 3
0
        public void Remove(string key)
        {
            var actKey = key;             // GetTaggedKey(key);

            if (this.SettingsData.ContainsKey(actKey))
            {
                var args = new SettingChangeEventArgs(key, this.SettingsData[actKey], null);
                this.OnSettingChanging(args);
                this.SettingsData.Remove(actKey);
                this.OnSettingChanged(args);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 子設定が変更されたとき、その値を保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void settings_SettingChanged(object sender, SettingChangeEventArgs e)
        {
            var settings = sender as SettingsContainer;

            if (settings != null)
            {
                var    tag = this.GetTaggedKey(settings.Tag, true);
                string str = null;
                using (var ms = new MemoryStream())
                {
                    this.ChildSettingsSerializer.Serialize(ms, settings);
                    ms.Seek(0, SeekOrigin.Begin);
                    using (var reader = new StreamReader(ms))
                    {
                        str = reader.ReadToEnd();
                    }
                }

                // 設定保存
                this.Set(tag, str);
            }
        }
Exemplo n.º 5
0
 private void SettingsContainer_SettingChanged(object sender, SettingChangeEventArgs e)
 {
     this.RaisePropertyChanged(e.Key);
 }