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, IPrioritizable, IDisplayable, INestedIdentifiable<Config>, INestedIdentifiable, IIdentifiableOwner<ConfigSection, IDefiningConfigKey>, IIdentifiableOwner<IDefiningConfigKey>, IIdentifiable
- 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
templateKeyITypedConfigKey<T>The typed name-only config item to match.
descriptionstringThe human-readable description of this config item.
computeDefaultFunc<T>The function that computes a default value for this key. Otherwise
default(will be used.T)internalAccessOnlyboolIf
true, only the owning mod should have access to this config item.valueValidatorPredicate<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
TThe 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
templateKeyITypedConfigKey<T>The typed name-only config item to match.
descriptionstringThe human-readable description of this config item.
computeDefaultFunc<T>The function that computes a default value for this key. Otherwise
default(will be used.T)internalAccessOnlyboolIf
true, only the owning mod should have access to this config item.valueValidatorPredicate<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
TThe 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
sourceJObjectThe Newtonsoft.Json.Linq.JObject being deserialized from. May be empty for when file didn't have it yet.
jsonSerializerJsonSerializerThe 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
typedTemplateKeyITypedConfigKey<T>The typed name-only config item to match.
typedDefiningKeyIDefiningConfigKey<T>The optional output of the found or created defining config item. Will also contain a match not from this config section.
descriptionstringThe human-readable description of this config item.
computeDefaultFunc<T>The function that computes a default value for this key. Otherwise
default(will be used.T)internalAccessOnlyboolIf
true, only the owning mod should have access to this config item.valueValidatorPredicate<T>The function that checks if the given value is valid for this config item. Otherwise everything will be accepted.
Returns
- bool
trueif a config item matching thetypedTemplateKeywas found or created; otherwise,false.
Type Parameters
TThe type of the config item's value.