You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.6 KiB

  1. using System;
  2. using System.IO;
  3. using IPA.Config.Data;
  4. namespace IPA.Config
  5. {
  6. /// <summary>
  7. /// An interface for configuration providers.
  8. /// </summary>
  9. /// <remarks>
  10. /// <para>
  11. /// Implementers must provide a default constructor. Do not assume that <see cref="File"/> will ever be set for a given object.
  12. /// </para>
  13. /// <para>
  14. /// Implementers are expected to preserve the typing of values passed to <see cref="Store"/> when returned from <see cref="Load"/>.
  15. /// The only exceptions to this are the numeric types, <see cref="Integer"/> and <see cref="FloatingPoint"/>, since they can be coerced
  16. /// to each other with <see cref="Integer.AsFloat"/> and <see cref="FloatingPoint.AsInteger"/> respectively. The provider <i>should</i>
  17. /// however store and recover <see cref="Integer"/> with as much precision as is possible. For example, a JSON provider may decide to
  18. /// decode all numbers that have an integral value, even if they were originally <see cref="FloatingPoint"/>, as <see cref="Integer"/>.
  19. /// This is reasonable, as <see cref="Integer"/> is more precise, particularly with larger values, than <see cref="FloatingPoint"/>.
  20. /// </para>
  21. /// </remarks>
  22. public interface IConfigProvider
  23. {
  24. /// <summary>
  25. /// Gets the extension <i>without</i> a dot to use for files handled by this provider.
  26. /// </summary>
  27. /// <remarks>
  28. /// This must work immediately, and is used to generate the <see cref="FileInfo"/> used to set
  29. /// <see cref="File"/>.
  30. /// </remarks>
  31. string Extension { get; }
  32. /// <summary>
  33. /// Sets the file that this provider will read and write to.
  34. /// </summary>
  35. /// <remarks>
  36. /// The provider is expected to gracefully handle this changing at any point,
  37. /// and is expected to close any old file handles when this is reassigned.
  38. /// This may be set to the same file multiple times in this object's lifetime.
  39. /// This will always have been set at least once before any calls to <see cref="Load"/>
  40. /// or <see cref="Store"/> are made.
  41. /// </remarks>
  42. FileInfo File { set; }
  43. /// <summary>
  44. /// Stores the <see cref="Value"/> given to disk in the format specified.
  45. /// </summary>
  46. /// <param name="value">the <see cref="Value"/> to store</param>
  47. void Store(Value value);
  48. /// <summary>
  49. /// Loads a <see cref="Value"/> from disk in whatever format this provider provides
  50. /// and returns it.
  51. /// </summary>
  52. /// <returns>the <see cref="Value"/> loaded</returns>
  53. Value Load();
  54. }
  55. }