Class ExpandoConfigSection
- Namespace
- MonkeyLoader.Configuration
- Assembly
- MonkeyLoader.dll
Represents a section of a Config for any IConfigOwner, which additional config items can be added to dynamically.
public abstract class ExpandoConfigSection : ConfigSection, INestedIdentifiable<Config>, INestedIdentifiable, IIdentifiableOwner<ConfigSection, IDefiningConfigKey>, IIdentifiableOwner<IDefiningConfigKey>, IIdentifiable, IPrioritizable
- Inheritance
-
ExpandoConfigSection
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
Use your mod's Config instance to load sections.
Properties
JsonSerializer
Gets the Newtonsoft.Json.JsonSerializer that added DefiningConfigKey<T>s will be attempted to be deserialized with.
protected JsonSerializer JsonSerializer { get; }
Property Value
- JsonSerializer
Source
Gets the source Newtonsoft.Json.Linq.JObject that added DefiningConfigKey<T>s will be attempted to be deserialized from.
protected JObject Source { get; }
Property Value
- JObject
Methods
CreateDefiningKey<T>(ITypedConfigKey<T>, string?, Func<T>?, bool, Predicate<T?>?)
Creates a new DefiningConfigKey<T> in this config section.
public IDefiningConfigKey<T> CreateDefiningKey<T>(ITypedConfigKey<T> templateKey, string? description = null, Func<T>? computeDefault = null, bool internalAccessOnly = false, Predicate<T?>? valueValidator = null)
Parameters
templateKey
ITypedConfigKey<T>The typed name-only config item to match.
description
stringThe human-readable description of this config item.
computeDefault
Func<T>The function that computes a default value for this key. Otherwise
default(
will be used.T
)internalAccessOnly
boolIf
true
, only the owning mod should have access to this config item.valueValidator
Predicate<T>The function that checks if the given value is valid for this config item. Otherwise everything will be accepted.
Returns
- IDefiningConfigKey<T>
The created defining config item.
Type Parameters
T
The type of the config item's value.
Exceptions
- InvalidOperationException
When there is already a config item that matches the name defined.
GetOrCreateDefiningKey<T>(ITypedConfigKey<T>, string?, Func<T>?, bool, Predicate<T?>?)
Tries to get a config item defined by this config section,
which matches the templateKey
's name and type.
Creates a new DefiningConfigKey<T> if no item with that name exists yet.
public IDefiningConfigKey<T> GetOrCreateDefiningKey<T>(ITypedConfigKey<T> templateKey, string? description = null, Func<T>? computeDefault = null, bool internalAccessOnly = false, Predicate<T?>? valueValidator = null)
Parameters
templateKey
ITypedConfigKey<T>The typed name-only config item to match.
description
stringThe human-readable description of this config item.
computeDefault
Func<T>The function that computes a default value for this key. Otherwise
default(
will be used.T
)internalAccessOnly
boolIf
true
, only the owning mod should have access to this config item.valueValidator
Predicate<T>The function that checks if the given value is valid for this config item. Otherwise everything will be accepted.
Returns
- IDefiningConfigKey<T>
The found or created defining config item.
Type Parameters
T
The type of the config item's value.
Exceptions
- InvalidOperationException
When there is already a config item that matches the name defined by another section, or with the wrong type.
OnLoad(JObject, JsonSerializer)
Deserializes all keys of this
ConfigSection from the source
Newtonsoft.Json.Linq.JObject.
protected override void OnLoad(JObject source, JsonSerializer jsonSerializer)
Parameters
source
JObjectThe Newtonsoft.Json.Linq.JObject being deserialized from. May be empty for when file didn't have it yet.
jsonSerializer
JsonSerializerThe Newtonsoft.Json.JsonSerializer to deserialize objects with.
Remarks
By default: Deserializes all keys from the source
with the jsonSerializer
.
Exceptions
- ConfigLoadException
When the value for a key fails to deserialize.
TryGetOrCreateDefiningKey<T>(ITypedConfigKey<T>, out IDefiningConfigKey<T>?, string?, Func<T>?, bool, Predicate<T?>?)
Tries to get a config item defined by this config section,
which matches the typedTemplateKey
's name and type.
Creates a new DefiningConfigKey<T> if no item with that name exists yet.
The found or created item is returned as typedDefiningKey
.
public bool TryGetOrCreateDefiningKey<T>(ITypedConfigKey<T> typedTemplateKey, out IDefiningConfigKey<T>? typedDefiningKey, string? description = null, Func<T>? computeDefault = null, bool internalAccessOnly = false, Predicate<T?>? valueValidator = null)
Parameters
typedTemplateKey
ITypedConfigKey<T>The typed name-only config item to match.
typedDefiningKey
IDefiningConfigKey<T>The optional output of the found or created defining config item. Will also contain a match not from this config section.
description
stringThe human-readable description of this config item.
computeDefault
Func<T>The function that computes a default value for this key. Otherwise
default(
will be used.T
)internalAccessOnly
boolIf
true
, only the owning mod should have access to this config item.valueValidator
Predicate<T>The function that checks if the given value is valid for this config item. Otherwise everything will be accepted.
Returns
- bool
true
if a config item matching thetypedTemplateKey
was found or created; otherwise,false
.
Type Parameters
T
The type of the config item's value.