IMoBroSettings
Provides access to the plugin's settings values.
note
The settings fields need to be configured in the mobro_plugin_config.json
file.
See the In-depth: Settings section for more details.
Functions
GetValue<T>(string): T
Retrieves the current value of a setting for the given key.
Throws a PluginSettingsException
if the setting does not exist or has no value.
Types
T
: The type to retrieve the setting value as (e.g.,bool
).
Parameters
Name | Type | Description |
---|---|---|
key | string | The key of the setting to retrieve. |
Returns
The current value of the setting.
Throws
PluginSettingsException
: If the setting does not exist or has no value.PluginException
: If an error occurs while parsing the setting value.
Example
_settings.GetValue<int>("update_frequency");
GetValue<T>(string, T): T
Retrieves the current value of a setting for the given key.
If no value is set, the specified default value is returned.
Types
T
: The type to retrieve the setting value as (e.g.,bool
).
Parameters
Name | Type | Description |
---|---|---|
key | string | The key of the setting to retrieve. |
defaultValue | T | The default value to return if the setting has no value set. |
Returns
The current value of the setting if set; otherwise, the default value.
Throws
PluginException
: If an error occurs while parsing the setting value.
Example
_settings.GetValue<int>("update_frequency", 1000);
TryGetValue<T>(string, out T): bool
Attempts to retrieve the current value of a setting for the given key.
Types
T
: The type to retrieve the setting value as (e.g.,bool
).
Parameters
Name | Type | Description |
---|---|---|
key | string | The key of the setting to retrieve. |
value | T (out) | When this method returns, contains the value associated with the specified key, if the key is found. Otherwise, contains the default value for the type of the value parameter. This parameter is uninitialized. |
Returns
Returns true
if the setting with the specified key is found; otherwise, false
.
Throws
PluginException
: If an error occurs while parsing the setting value.
Example
if (_settings.TryGetValue<int>("update_frequency", out var updateFrequency))
{
Console.WriteLine($"Configured update frequency: {updateFrequency}");
}
else
{
// The setting with key 'update_frequency' does not have a value.
}