Exemple #1
0
        void SetValue(SettingsID settingID, string value)
        {
            //validate
            if (IsReadOnly(settingID))
            {
                return;
            }

            //get type
            var dataType = (settingID.GetType().GetMember(settingID.ToString())[0].GetCustomAttributes(typeof(DataTypeAttribute), false)[0] as DataTypeAttribute).Type;

            //convert
            var convertedValue = ParamerterConverter.ChangeType(value, dataType);

            //set value
            var id = (int)settingID;

            if (_settings.ContainsKey(id))
            {
                _settings[id] = convertedValue;
            }
            else
            {
                _settings.Add(id, convertedValue);
            }
        }
Exemple #2
0
 public SettingWriteCommand[] GetWriteCommands()
 {
     return((from s in _settings
             select new SettingWriteCommand()
     {
         SettingID = s.Key, Value = ParamerterConverter.SerializeValue(s.Value, true)
     }).ToArray());
 }
Exemple #3
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)
                }
            });
        }