/// <summary> /// Set the settings value internally. /// </summary> /// <param name="id">The setting id.</param> /// <param name="value">The setting value.</param> internal void SetSettingsPair(SettingsRegistry id, int value) { // For each setting. for (int i = 0; i < _settings.Length; i++) { // Get the item. SettingsPair item = _settings[i]; // If the id has been found. if (id == item.Id) { // Set the new value. _settings[i].Value = value; } } }
public void SettingsRegistryTest() { SettingsRegistry registry = new SettingsRegistry(); registry.SettingRegistered += Registry_SettingRegistered; TestSettingsSetSetting setting1 = new TestSettingsSetSetting(); registry.Register(setting1); registry.SettingRegistered -= Registry_SettingRegistered; TempRegister(registry); TempRegister(registry, "key2", "description"); GC.Collect(2, GCCollectionMode.Forced, false, false); TempRegister(registry); TempRegister(registry, "key2", "description"); Assert.ThrowsException <ArgumentException>(() => TempRegister(registry, description: "different description")); Assert.ThrowsException <ArgumentNullException>(() => registry.Register(null !)); }
/// <summary> /// Settings pair. /// </summary> /// <param name="id">Settings id.</param> /// <param name="value">Setting value.</param> public SettingsPair(SettingsRegistry id, int value) { _bufferSegment = new ArraySegment <byte>(new byte[PairSize], 0, PairSize); Id = id; Value = value; }
private void TempRegister(SettingsRegistry registry, string key = null, string description = null) { TestSettingsSetSetting setting2 = new TestSettingsSetSetting(key ?? "key", "defaultValue", description); registry.Register(setting2); }