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.

103 lines
5.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace IPA
  7. {
  8. /// <summary>
  9. /// An interface for configuration providers.
  10. /// </summary>
  11. public interface IConfigProvider
  12. {
  13. /// <summary>
  14. /// Loads the data provided by this <see cref="IConfigProvider"/> into an object of type <typeparamref name="T"/>.
  15. /// </summary>
  16. /// <typeparam name="T">the type of the object to parse into</typeparam>
  17. /// <returns>the values from the config provider parsed into the object</returns>
  18. T Parse<T>();
  19. /// <summary>
  20. /// Stores the data from <paramref name="obj"/> into the <see cref="IConfigProvider"/>.
  21. /// </summary>
  22. /// <remarks>
  23. /// NOTE TO IMPLEMENTERS:
  24. /// Since <see cref="Newtonsoft.Json"/> is bundled with this library, try to include support for its attributes.
  25. /// </remarks>
  26. /// <typeparam name="T">the type of <paramref name="obj"/></typeparam>
  27. /// <param name="obj">the object containing the data to save</param>
  28. void Store<T>(T obj);
  29. #region Getters
  30. /// <summary>
  31. /// Gets the <see cref="IConfigProvider"/> acting as a sub-object for a given key.
  32. /// </summary>
  33. /// <param name="name">the name of the field with the <see cref="IConfigProvider"/></param>
  34. /// <returns>an accessor for the selected sub-object</returns>
  35. IConfigProvider GetSubObject(string name);
  36. /// <summary>
  37. /// Gets the value of type <typeparamref name="T"/> for key <paramref name="name"/>.
  38. /// </summary>
  39. /// <remarks>
  40. /// If <typeparamref name="T"/> is <see cref="IConfigProvider"/>, behavior should be identical to <see cref="GetSubObject"/>.
  41. /// </remarks>
  42. /// <typeparam name="T">the type of the value to get</typeparam>
  43. /// <param name="name">the name of the field to get the value of</param>
  44. /// <returns>the value of the field</returns>
  45. T Get<T>(string name); // can be IConfigProvider
  46. /// <summary>
  47. /// The non-generic version of <see cref="Get{T}"/>.
  48. /// If key corresponds to a sub-object, will return an <see cref="IConfigProvider"/>.
  49. /// </summary>
  50. /// <param name="name">the name of the field to get the value of</param>
  51. /// <returns>the value of the field</returns>
  52. object Get(string name); // can return IConfigProvider
  53. /// <summary>
  54. /// Gets the value of type <typeparamref name="T"/> of the element at <paramref name="path"/>.
  55. /// </summary>
  56. /// <remarks>
  57. /// If <typeparamref name="T"/> is <see cref="IConfigProvider"/>, behavior should be identical to <see cref="GetSubObject"/> if it were executed on the immediate parent of the target element.
  58. /// </remarks>
  59. /// <typeparam name="T">the type of the value to get</typeparam>
  60. /// <param name="path">an ordered array specifying keys starting from the root (this)</param>
  61. /// <returns>the value at path</returns>
  62. T GetPath<T>(params string[] path);
  63. /// <summary>
  64. /// The non-generic version of <see cref="GetPath{T}(string[])"/>.
  65. /// If key corresponds to a sub-object, will return an <see cref="IConfigProvider"/>.
  66. /// </summary>
  67. /// <param name="path">an ordered array specifying keys starting from the root (this)</param>
  68. /// <returns>the value at path</returns>
  69. object GetPath(params string[] path);
  70. #endregion
  71. #region Setters
  72. /// <summary>
  73. /// Sets the object for key '<paramref name="name"/>' to <paramref name="provider"/>.
  74. /// </summary>
  75. /// <param name="name">the key to set it as</param>
  76. /// <param name="provider">the provider value</param>
  77. void SetSubObject(string name, IConfigProvider provider); // argument should be same provider type
  78. /// <summary>
  79. /// Sets the value for key <paramref name="name"/> to <paramref name="value"/>.
  80. /// </summary>
  81. /// <remarks>
  82. /// If <typeparamref name="T"/> is <see cref="IConfigProvider"/>, behavior should be identical to <see cref="SetSubObject(string, IConfigProvider)"/>.
  83. /// </remarks>
  84. /// <typeparam name="T">the type of the value to set</typeparam>
  85. /// <param name="name">the key</param>
  86. /// <param name="value">the value to set</param>
  87. void Set<T>(string name, T value);
  88. /// <summary>
  89. /// Sets the value for path <paramref name="path"/> to <paramref name="value"/>.
  90. /// </summary>
  91. /// <remarks>
  92. /// If <typeparamref name="T"/> is <see cref="IConfigProvider"/>, behavior should be identical to <see cref="SetSubObject(string, IConfigProvider)"/> if it were executed on the immediate parent of the target element.
  93. /// </remarks>
  94. /// <typeparam name="T">the type of the value to set</typeparam>
  95. /// <param name="path">the path to the new value location</param>
  96. /// <param name="value">the value to set</param>
  97. void SetPath<T>(string[] path, T value);
  98. #endregion
  99. }
  100. }