using System;
namespace BepInEx.Configuration
{
///
/// Provides access to a single setting inside of a .
///
/// Type of the setting.
public sealed class ConfigWrapper : ConfigEntryBase
{
///
/// Fired when the setting is changed. Does not detect changes made outside from this object.
///
public event EventHandler SettingChanged;
private T _typedValue;
///
/// Value of this setting.
///
public T Value
{
get => _typedValue;
set
{
value = ClampValue(value);
if (Equals(_typedValue, value))
return;
_typedValue = value;
OnSettingChanged(this);
}
}
///
public override object BoxedValue
{
get => Value;
set => Value = (T)value;
}
internal ConfigWrapper(ConfigFile configFile, ConfigDefinition definition, T defaultValue) : base(configFile, definition, typeof(T), defaultValue)
{
configFile.SettingChanged += (sender, args) =>
{
if (args.ChangedSetting == this) SettingChanged?.Invoke(sender, args);
};
}
}
}