IMoBroSettings
Provides access to the plugin's settings values.
The settings fields need to be defined in the mobro_plugin_config.json file.
See In-depth: Plugin Settings for more details.
Supported Types
Settings values are transferred as strings and converted to the requested type T. The following types are supported:
T | Use for |
|---|---|
string | string and select fields |
bool | checkbox fields |
double | number fields |
int | number fields that only accept whole numbers |
Requesting any other type, or a value that can't be converted (e.g. 2.5 as int), throws a
PluginSettingsException.
Functions
GetValue<T>(string): T
Retrieves the current value of a setting.
Parameters
| Name | Type | Description |
|---|---|---|
key | string | The name of the settings field. |
Returns
The current value of the setting.
Throws
PluginSettingsException: If the setting has no value, or the value can't be converted toT.
Example
var updateFrequency = _settings.GetValue<int>("update_frequency");
Let the PluginSettingsException thrown by GetValue<T> propagate from Init(). MoBro then reports a settings error
for the affected field instead of a generic plugin error.
GetValue<T>(string, T): T
Retrieves the current value of a setting, or the given default value if the setting has no value.
Parameters
| Name | Type | Description |
|---|---|---|
key | string | The name of the settings field. |
defaultValue | T | The value to return if the setting has no value. |
Throws
PluginSettingsException: If a value is set but can't be converted toT.
Example
var processCount = _settings.GetValue("num_processes", 5);
TryGetValue<T>(string, out T): bool
Attempts to retrieve the current value of a setting.
Parameters
| Name | Type | Description |
|---|---|---|
key | string | The name of the settings field. |
value | T (out) | Contains the value if the setting has one; otherwise the default value of T. |
Returns
true if the setting has a value; otherwise false.
Example
if (_settings.TryGetValue<string>("api_key", out var apiKey))
{
_apiClient.Authenticate(apiKey);
}