public static object ExtractValue(this ISettingPreset settingPreset, string value) { if (settingPreset == null) { return(null); } ISetting setting = new SettingImplement(settingPreset.Setting.Type, settingPreset.Setting.Code, value); return(setting.Value); }
private static void AddSettingsSet( IEnumerable <ISettingPreset> settingPresets, SettingRedefinition[] redefinitions, Action <int, string> addSettingAction) { foreach (ISettingPreset settingPreset in settingPresets) { SettingRedefinition redefinition = redefinitions?.FirstOrDefault(x => x.SettingPublicId == settingPreset.SettingPublicId); if (redefinition != null) { SettingImplement settingImplement = new SettingImplement( settingPreset.Setting.Type, settingPreset.Setting.Code, redefinition.NewValue); if (!settingImplement.IsValid( settingPreset.Value.MinValue, settingPreset.Value.MaxValue, settingPreset.IsRequired)) { throw new InvariantViolationException( $"Invalid value definition ('{redefinition.NewValue}') " + $"for settings preset ({settingPreset.GetSettingPresetType()}:'{settingPreset.PresetId}'," + $"min:'{settingPreset.Value.MinValue}',max:'{settingPreset.Value.MaxValue}')", SettingsPresetErrorCode.SettingValueDefinitionIsInvalid); } } string value = redefinition != null ? redefinition.NewValue : settingPreset.Value.DefaultValue; addSettingAction(settingPreset.SettingId, value); } }