ConfigWrapper.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. namespace BepInEx.Configuration
  3. {
  4. /// <summary>
  5. /// Provides access to a single setting inside of a <see cref="Configuration.ConfigFile"/>.
  6. /// </summary>
  7. /// <typeparam name="T">Type of the setting.</typeparam>
  8. [Obsolete("Use ConfigFile from new AddSetting overloads instead")]
  9. public sealed class ConfigWrapper<T>
  10. {
  11. /// <summary>
  12. /// Entry of this setting in the <see cref="Configuration.ConfigFile"/>.
  13. /// </summary>
  14. public ConfigEntry<T> ConfigEntry { get; }
  15. /// <summary>
  16. /// Unique definition of this setting.
  17. /// </summary>
  18. public ConfigDefinition Definition => ConfigEntry.Definition;
  19. /// <summary>
  20. /// Config file this setting is inside of.
  21. /// </summary>
  22. public ConfigFile ConfigFile => ConfigEntry.ConfigFile;
  23. /// <summary>
  24. /// Fired when the setting is changed. Does not detect changes made outside from this object.
  25. /// </summary>
  26. public event EventHandler SettingChanged;
  27. /// <summary>
  28. /// Value of this setting.
  29. /// </summary>
  30. public T Value
  31. {
  32. get => ConfigEntry.Value;
  33. set => ConfigEntry.Value = value;
  34. }
  35. internal ConfigWrapper(ConfigEntry<T> configEntry)
  36. {
  37. ConfigEntry = configEntry ?? throw new ArgumentNullException(nameof(configEntry));
  38. configEntry.ConfigFile.SettingChanged += (sender, args) =>
  39. {
  40. if (args.ChangedSetting == configEntry) SettingChanged?.Invoke(sender, args);
  41. };
  42. }
  43. }
  44. }