Table of Contents

Class Config

Namespace
MonkeyLoader.Configuration
Assembly
MonkeyLoader.dll

The configuration for a mod. Each mod has exactly one configuration.
The configuration object will never be reassigned once initialized.

public sealed class Config : INestedIdentifiable<IConfigOwner>, INestedIdentifiable, IIdentifiableOwner<Config, ConfigSection>, IIdentifiableOwner<ConfigSection>, INestedIdentifiableOwner<IDefiningConfigKey>, IIdentifiable
Inheritance
Config
Implements
Inherited Members
Extension Methods

Properties

ConfigurationItemDefinitions

Gets the config keys defined in this configuration.

public IEnumerable<IDefiningConfigKey> ConfigurationItemDefinitions { get; }

Property Value

IEnumerable<IDefiningConfigKey>

FullId

Gets the fully qualified identifier for this item.
Should be implemented explicitly in non-INestedIdentifiables.

public string FullId { get; }

Property Value

string

Should be: {Parent.FullId}.{Id}, or just Id for top level items.

this[IConfigKey]

Gets or sets a configuration value for the given key, throwing a KeyNotFoundException if the key is not found. May throw an ArgumentException if the value is not valid for it.

public object? this[IConfigKey key] { get; set; }

Parameters

key IConfigKey

The key to get or set the value for.

Property Value

object

Remarks

This shorthand does not exist for GetValue<T>(ITypedConfigKey<T>), because generic indexers aren't supported.

Exceptions

KeyNotFoundException

The given key does not exist in the configuration.

ArgumentException

The new value is not valid for the given key.

Logger

Gets the logger used by this config.

public Logger Logger { get; }

Property Value

Logger

Owner

Gets the mod that owns this config.

public IConfigOwner Owner { get; }

Property Value

IConfigOwner

Sections

Gets all loaded sections of this config.

public IEnumerable<ConfigSection> Sections { get; }

Property Value

IEnumerable<ConfigSection>

Methods

GetValue(IConfigKey)

Gets the configuration value for the given key, throwing a KeyNotFoundException if the key is not found.

public object? GetValue(IConfigKey key)

Parameters

key IConfigKey

The key to get the value for.

Returns

object

The value for the key.

Exceptions

KeyNotFoundException

The given key does not exist in the configuration.

GetValue<T>(ITypedConfigKey<T>)

Gets the configuration value for the given key, throwing a KeyNotFoundException if the key is not found.

public T GetValue<T>(ITypedConfigKey<T> key)

Parameters

key ITypedConfigKey<T>

The key to get the value for.

Returns

T

The value for the key.

Type Parameters

T

The type of the key's value.

Exceptions

KeyNotFoundException

The given key does not exist in the configuration.

IsKeyDefined(IConfigKey)

Checks if the given key is defined in this config.

public bool IsKeyDefined(IConfigKey key)

Parameters

key IConfigKey

The key to check.

Returns

bool

true if the key is defined.

LoadSection<TSection>()

Loads a section with a parameterless constructor based on its type.
Every section can only be loaded once.

public TSection LoadSection<TSection>() where TSection : ConfigSection, new()

Returns

TSection

The loaded section.

Type Parameters

TSection

The type of the section to load.

Exceptions

ConfigLoadException

If section has already been loaded, or something goes wrong while loading.

LoadSection<TSection>(TSection)

Loads the given section.
Every section can only be loaded once.

public TSection LoadSection<TSection>(TSection section) where TSection : ConfigSection

Parameters

section TSection

Returns

TSection

The loaded section.

Type Parameters

TSection

The type of the section to load.

Exceptions

ConfigLoadException

If section has already been loaded, or something goes wrong while loading.

Reset()

Removes the value of all of this configuration's sections' keys and resets them to their default.

public void Reset()

Save()

Persists this configuration to disk.

public void Save()

SetValue(IConfigKey, object?, string?)

Sets a configuration value for the given key, throwing a KeyNotFoundException if the key is not found or an ArgumentException if the value is not valid for it.

public void SetValue(IConfigKey key, object? value, string? eventLabel = null)

Parameters

key IConfigKey

The key to get the value for.

value object

The new value to set.

eventLabel string

A custom label you may assign to this change event.

Exceptions

KeyNotFoundException

The given key does not exist in the configuration.

ArgumentException

The new value is not valid for the given key.

SetValue<T>(ITypedConfigKey<T>, T, string?)

Sets a configuration value for the given key, throwing a KeyNotFoundException if the key is not found or an ArgumentException if the value is not valid for it.

public void SetValue<T>(ITypedConfigKey<T> key, T value, string? eventLabel = null)

Parameters

key ITypedConfigKey<T>

The key to get the value for.

value T

The new value to set.

eventLabel string

A custom label you may assign to this change event.

Type Parameters

T

The type of the config item's value.

Exceptions

KeyNotFoundException

The given key does not exist in the configuration.

ArgumentException

The new value is not valid for the given key.

TryGetDefiningKey(IConfigKey, out IDefiningConfigKey?)

Tries to get the defining key in this config for the given key.

public bool TryGetDefiningKey(IConfigKey key, out IDefiningConfigKey? definingKey)

Parameters

key IConfigKey

The key to check.

definingKey IDefiningConfigKey

The defining key in this config when this returns true, otherwise null.

Returns

bool

true if the key is defined in this config.

TryGetDefiningKey<T>(ITypedConfigKey<T>, out IDefiningConfigKey<T>?)

Tries to get the defining key in this config for the given key.

public bool TryGetDefiningKey<T>(ITypedConfigKey<T> key, out IDefiningConfigKey<T>? definingKey)

Parameters

key ITypedConfigKey<T>

The key to check.

definingKey IDefiningConfigKey<T>

The defining key in this config when this returns true, otherwise null.

Returns

bool

true if the key is defined in this config.

Type Parameters

T

The type of the config item's value.

TryGetValue(IConfigKey, out object?)

Tries to get a value, returning null if the key is not found.

public bool TryGetValue(IConfigKey key, out object? value)

Parameters

key IConfigKey

The key to get the value for.

value object

The value if the return value is true, or default if false.

Returns

bool

true if the value was read successfully.

TryGetValue<T>(ITypedConfigKey<T>, out T?)

Tries to get a value, returning default(T) if the key is not found.

public bool TryGetValue<T>(ITypedConfigKey<T> key, out T? value)

Parameters

key ITypedConfigKey<T>

The key to get the value for.

value T

The value if the return value is true, or default if false.

Returns

bool

true if the value was read successfully.

Type Parameters

T

The type of the config item's value.

Unset(IConfigKey)

Removes a key's value, throwing a KeyNotFoundException if the key is not found.

public bool Unset(IConfigKey key)

Parameters

key IConfigKey

The key to remove the value for.

Returns

bool

true if a value was successfully found and removed, false if there was no value to remove.

Exceptions

KeyNotFoundException

The given key does not exist in the configuration.

Events

ItemChanged

Called when the value of one of this config's items gets changed.

public event ConfigKeyChangedEventHandler? ItemChanged

Event Type

ConfigKeyChangedEventHandler