Class DefiningConfigKey<T>
- Namespace
- MonkeyLoader.Configuration
- Assembly
- MonkeyLoader.dll
Represents the typed definition for a config item.
public sealed class DefiningConfigKey<T> : Entity<DefiningConfigKey<T>>, IEntity<DefiningConfigKey<T>>, IEnumerable<IComponent<DefiningConfigKey<T>>>, IDefiningConfigKey<T>, IDefiningConfigKey, IEntity<IDefiningConfigKey>, IEnumerable<IComponent<IDefiningConfigKey>>, INestedIdentifiable<ConfigSection>, INestedIdentifiable, IPrioritizable, IDisplayable, ITypedConfigKey<T>, ITypedConfigKey, IConfigKey, IEquatable<IConfigKey>, IIdentifiable, IEntity<IDefiningConfigKey<T>>, IEnumerable<IComponent<IDefiningConfigKey<T>>>, IEnumerable
Type Parameters
TThe type of the config item's value.
- Inheritance
-
DefiningConfigKey<T>
- Implements
- Inherited Members
- Extension Methods
Remarks
Add extra components like this:
DefiningConfigKey<int> testKey = new("Test", ...)
{
new ConfigKeyRange<int>(0, 255)
};
Constructors
DefiningConfigKey(string, string?, Func<T>?, bool, Predicate<T?>?)
Creates a new instance of the DefiningConfigKey<T> class with the given parameters.
public DefiningConfigKey(string id, string? description = null, Func<T>? computeDefault = null, bool internalAccessOnly = false, Predicate<T?>? valueValidator = null)
Parameters
idstringThe mod-unique identifier of this config item. Must not be null or whitespace.
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.
Remarks
The Changed event will be fired whenever the equality comparison of the value of this key changes.
If the value type implements INotifyPropertyChanged or INotifyCollectionChanged,
those events will be passed through as well.
Add extra components like this:
DefiningConfigKey<int> testKey = new("Test", ...)
{
new ConfigKeyRange<int>(0, 255)
};
Exceptions
- ArgumentNullException
If the
idis null or whitespace.
Properties
AsUntyped
Gets the untyped version of this config item.
public IConfigKey AsUntyped { get; }
Property Value
Config
Gets the config this item belongs to.
public Config Config { get; }
Property Value
Description
Gets the optional human-readable description to display for this item.
public string? Description { get; }
Property Value
FullId
Gets the fully unique identifier for this config item.
public string FullId { get; }
Property Value
Remarks
HasChanges
Gets or sets whether this config item has unsaved changes.
public bool HasChanges { get; set; }
Property Value
HasDescription
Gets whether this item has a description.
public bool HasDescription { get; }
Property Value
HasValue
Gets whether this config item has a set value.
public bool HasValue { get; }
Property Value
Remarks
Should be automatomatically set to true when a different value is set.
Id
Gets the mod-unique identifier of this config item.
public string Id { get; }
Property Value
InternalAccessOnly
Gets whether only the owning mod should have access to this config item.
public bool InternalAccessOnly { get; }
Property Value
IsDefiningKey
Gets whether this instance defines the config item with this name.
public bool IsDefiningKey { get; }
Property Value
Priority
Gets the priority of this item. Use an agreed standard as a base.
public int Priority { get; init; }
Property Value
- int
An interger used to sort the prioritizable items.
Higher comes first with the default comparer.
Remarks
Add a priority component to this config key or set a value during initialization.
Section
Gets the ConfigSection this item belongs to.
public ConfigSection Section { get; set; }
Property Value
Remarks
Should only be set once when the owning ConfigSection is initializing.
ValueType
Gets the Type of this config item's value.
public Type ValueType { get; }
Property Value
Methods
Equals(IConfigKey)
public bool Equals(IConfigKey other)
Parameters
otherIConfigKey
Returns
Equals(object)
public override bool Equals(object obj)
Parameters
objobject
Returns
GetEnumerator()
public IEnumerator<IComponent<IDefiningConfigKey>> GetEnumerator()
Returns
GetHashCode()
public override int GetHashCode()
Returns
GetValue()
Gets this config item's set value, falling back to the computed default.
public T? GetValue()
Returns
- T
The item's internal value or its type's
default.
Reset()
Removes this config item's value and attempts to reset it back to its default.
public void Reset()
SetValue(T, string?)
Set the config item's internal value to the given one.
public void SetValue(T value, string? eventLabel = null)
Parameters
valueTThe value to set.
eventLabelstringThe custom label that may be set by whoever changed the config.
Exceptions
- ArgumentException
Tthe
valuedidn't pass validation.
TryComputeDefault(out T?)
Tries to compute the default value for this key, if a default provider was set.
public bool TryComputeDefault(out T? defaultValue)
Parameters
defaultValueTThe computed default value if the return value is
true. Otherwisedefault.
Returns
- bool
trueif the default value was successfully computed.
TryGetValue(out T?)
Tries to get this config item's set value, falling back to the computed default.
public bool TryGetValue(out T? value)
Parameters
valueTThe item's internal value or its type's
default.
Returns
- bool
trueif the config item's value was set or a default could be computer, otherwisefalse.
TrySetValue(T, string?)
Tries to set the config item's internal value to the given one if it passes validation.
public bool TrySetValue(T value, string? eventLabel = null)
Parameters
valueTThe value to set.
eventLabelstringThe custom label that may be set by whoever changed the config.
Returns
- bool
trueif the value was successfully set, otherwisefalse.
Unset()
Removes this config item's value, setting it to its type's default.
public bool Unset()
Returns
- bool
Whether there was a value to remove.
Validate(T)
Checks if a value is valid for this config item.
public bool Validate(T value)
Parameters
valueTThe value to check.
Returns
- bool
trueif the value is valid.
Events
Changed
Triggered when the internal value of this config item changes.
public event ConfigKeyChangedEventHandler<T>? Changed
Event Type
Operators
implicit operator T?(DefiningConfigKey<T>)
Implicitly gets the value of this config item.
public static implicit operator T?(DefiningConfigKey<T> key)
Parameters
keyDefiningConfigKey<T>The config item to get the value of.
Returns
- T
The item's internal value or its type's
default.