Skip to main content

IMoBroSettings

Provides access to the plugins settings values

note

The settings fields need to be configured in the mobro_plugin_config.json file.
See In depth: Settings

Functions

GetValue<T>(string): T

Gets the current setting value for a given key
Raises a PluginSettingsException if the setting does not exist or has no value

Types

  • T: The type to get the settings value in (e.g. bool)

Parameters

NameTypeDescription
keystringThe key of the setting to get the value for

Returns

The current value of the setting

Throws

  • PluginSettingsException: The setting does not exist or is not set
  • PluginException: An error occurred while parsing the settings value

Example

_settings.GetValue<int>("update_frequency");

GetValue<T>(string, T): T

Gets the current setting value for a given key
If no value is set, the given default value is returned instead

Types

  • T: The type to get the settings value in (e.g. bool)

Parameters

NameTypeDescription
keystringThe key of the setting to get the value for
defaultValueTThe default value to return in case the setting has no value

Returns

The current value of the setting if set; the default value otherwise

Throws

  • PluginException: An error occurred while parsing the settings value

Example

_settings.GetValue<int>("update_frequency", 1000);

TryGetValue<T>(string, out T): bool

Gets the current setting value for a given key

Types

  • T: The type to get the settings value in (e.g. bool)

Parameters

NameTypeDescription
keystringThe key of the setting to get the value for
valueT (out)When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized

Returns

true if the setting with the specified key is found; otherwise false

Throws

  • PluginException: An error occurred while parsing the settings value

Example

if (_settings.TryGetValue<int>("update_frequency", out var updateFrequency)
{
Console.WriteLine($"Configured update frequency: {updateFrequency}");
}
else
{
// setting with key 'update_frequency' doesn't have a value
}