/// <summary> /// Sets the setting value. /// </summary> /// <param name="name">The name of the setting.</param> /// <param name="value">The value of the setting.</param> /// <param name="formType">The UI type that should be used to represent the value (not currently implemented).</param> public void SetValue(string name, string value, SettingFormType formType = SettingFormType.Textbox) { SettingValue settingValue = _values.FirstOrDefault(x => !string.IsNullOrEmpty(x.Name) && x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)); if (settingValue == null) { settingValue = new SettingValue(); settingValue.Name = name; _values.Add(settingValue); } settingValue.Value = value; settingValue.FormType = formType; }
private static string GetCleanValue(string input, SettingFormType formType) { switch (formType) { case SettingFormType.Checkbox: // Checkbox should be boolean. // The whole settings could be reworked as a generic class, // quite easy with JSON serialization, but for now let's just see // if the value provided by plugin creator is boolean, and if not - // - revert to default (which was, is, and probably will be False) bool o; if (!bool.TryParse(input, out o)) o = default(bool); return o.ToString(); default: return input; } }
/// <summary> /// Sets the setting value. /// </summary> /// <param name="name">The name of the setting.</param> /// <param name="value">The value of the setting.</param> /// <param name="formType">The UI type that should be used to represent the value (not currently implemented).</param> public void SetValue(string name, string value, SettingFormType formType = SettingFormType.Textbox) { SettingValue settingValue = _values.FirstOrDefault(x => !string.IsNullOrEmpty(x.Name) && x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)); if (settingValue == null) { settingValue = new SettingValue(); settingValue.Name = name; _values.Add(settingValue); } // Set form type first, so that the validation happens // Though the after-the-fact validation will work even // if done other way around. settingValue.FormType = formType; settingValue.Value = value; }
private static string GetCleanValue(string input, SettingFormType formType) { switch (formType) { case SettingFormType.Checkbox: // Checkbox should be boolean. // The whole settings could be reworked as a generic class, // quite easy with JSON serialization, but for now let's just see // if the value provided by plugin creator is boolean, and if not - // - revert to default (which was, is, and probably will be False) bool o; if (!bool.TryParse(input, out o)) { o = default(bool); } return(o.ToString()); default: return(input); } }