コード例 #1
0
 public SettingWriteCommand[] GetWriteCommands()
 {
     return((from s in _settings
             select new SettingWriteCommand()
     {
         SettingID = s.Key, Value = ParamerterConverter.SerializeValue(s.Value, true)
     }).ToArray());
 }
コード例 #2
0
        void Set <T>(SettingsID settingID, T value)
        {
            //validate
            var  oldValue   = Get <T>(settingID);
            bool hasChanged = !EqualityComparer <T> .Default.Equals(value, oldValue);

            if (!hasChanged)
            {
                return;
            }
            if (IsReadOnly(settingID))
            {
                return;
            }

            //set
            var id = (int)settingID;

            if (_settings.ContainsKey(id))
            {
                _settings[id] = value;
            }
            else
            {
                _settings.Add(id, value);
            }

            //send event
            SettingChanged?.Invoke(this, new SettingChangedEventArgs()
            {
                OldValue = oldValue, NewValue = value, WriteCommand = new SettingWriteCommand()
                {
                    SettingID = (int)settingID, Value = ParamerterConverter.SerializeValue(value, true)
                }
            });
        }