|
@@ -6,44 +6,44 @@ namespace BepInEx.Configuration
|
|
|
/// Provides access to a single setting inside of a <see cref="Configuration.ConfigFile"/>.
|
|
|
/// </summary>
|
|
|
/// <typeparam name="T">Type of the setting.</typeparam>
|
|
|
- public sealed class ConfigWrapper<T>
|
|
|
+ public sealed class ConfigWrapper<T> : ConfigEntryBase
|
|
|
{
|
|
|
/// <summary>
|
|
|
- /// Entry of this setting in the <see cref="Configuration.ConfigFile"/>.
|
|
|
- /// </summary>
|
|
|
- public ConfigEntry<T> ConfigEntry { get; }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Unique definition of this setting.
|
|
|
- /// </summary>
|
|
|
- public ConfigDefinition Definition => ConfigEntry.Definition;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Config file this setting is inside of.
|
|
|
- /// </summary>
|
|
|
- public ConfigFile ConfigFile => ConfigEntry.ConfigFile;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
/// Fired when the setting is changed. Does not detect changes made outside from this object.
|
|
|
/// </summary>
|
|
|
public event EventHandler SettingChanged;
|
|
|
|
|
|
+ private T _typedValue;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Value of this setting.
|
|
|
/// </summary>
|
|
|
public T Value
|
|
|
{
|
|
|
- get => ConfigEntry.TypedValue;
|
|
|
- set => ConfigEntry.TypedValue = value;
|
|
|
+ get => _typedValue;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ value = ClampValue(value);
|
|
|
+ if (Equals(_typedValue, value))
|
|
|
+ return;
|
|
|
+
|
|
|
+ _typedValue = value;
|
|
|
+ OnSettingChanged(this);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- internal ConfigWrapper(ConfigEntry<T> configEntry)
|
|
|
+ /// <inheritdoc />
|
|
|
+ public override object BoxedValue
|
|
|
{
|
|
|
- ConfigEntry = configEntry ?? throw new ArgumentNullException(nameof(configEntry));
|
|
|
+ get => Value;
|
|
|
+ set => Value = (T)value;
|
|
|
+ }
|
|
|
|
|
|
- configEntry.ConfigFile.SettingChanged += (sender, args) =>
|
|
|
+ internal ConfigWrapper(ConfigFile configFile, ConfigDefinition definition, T defaultValue) : base(configFile, definition, typeof(T), defaultValue)
|
|
|
+ {
|
|
|
+ configFile.SettingChanged += (sender, args) =>
|
|
|
{
|
|
|
- if (args.ChangedSetting == configEntry) SettingChanged?.Invoke(sender, args);
|
|
|
+ if (args.ChangedSetting == this) SettingChanged?.Invoke(sender, args);
|
|
|
};
|
|
|
}
|
|
|
}
|