ConfigDescription.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. namespace BepInEx.Configuration
  3. {
  4. /// <summary>
  5. /// Metadata of a <see cref="ConfigEntry"/>.
  6. /// </summary>
  7. public class ConfigDescription
  8. {
  9. /// <summary>
  10. /// Create a new description.
  11. /// </summary>
  12. /// <param name="description">Text describing the function of the setting and any notes or warnings.</param>
  13. /// <param name="acceptableValues">Range of values that this setting can take. The setting's value will be automatically clamped.</param>
  14. /// <param name="tags">Objects that can be used by user-made classes to add functionality.</param>
  15. public ConfigDescription(string description, AcceptableValueBase acceptableValues = null, params object[] tags)
  16. {
  17. AcceptableValues = acceptableValues;
  18. Tags = tags;
  19. Description = description ?? throw new ArgumentNullException(nameof(description));
  20. }
  21. /// <summary>
  22. /// Text describing the function of the setting and any notes or warnings.
  23. /// </summary>
  24. public string Description { get; }
  25. /// <summary>
  26. /// Range of acceptable values for a setting.
  27. /// </summary>
  28. public AcceptableValueBase AcceptableValues { get; }
  29. /// <summary>
  30. /// Objects that can be used by user-made classes to add functionality.
  31. /// </summary>
  32. public object[] Tags { get; }
  33. /// <summary>
  34. /// Convert the description object into a form suitable for writing into a config file.
  35. /// </summary>
  36. public string ToSerializedString()
  37. {
  38. return $"# {Description.Replace("\n", "\n# ")}";
  39. }
  40. }
  41. }