Genericise configurations

This is a breaking change. Enables easy creation of config files without copy/pasting the Read/Write code all the time
This commit is contained in:
Chris 2020-12-03 17:42:46 +10:30
parent 3776a71a20
commit a03647ce38
4 changed files with 919 additions and 0 deletions

View file

@ -0,0 +1,55 @@
namespace TShockAPI.Configuration
{
/// <summary>
/// Describes a generic configuration interface wrapping some settings
/// </summary>
/// <typeparam name="TSettings"></typeparam>
public interface IConfigFile<TSettings>
{
/// <summary>
/// Settings managed by this config file
/// </summary>
TSettings Settings { get; set; }
/// <summary>
/// Reads settings from a given path
/// </summary>
/// <param name="path">The path to the file containing the settings</param>
/// <param name="incompleteSettings">
/// Whether the settings object has any new fields in it, meaning that the configuration should be
/// overwritten.
/// </param>
/// <returns>Settings object</returns>
TSettings Read(string path, out bool incompleteSettings);
/// <summary>
/// Reads settings from a given stream
/// </summary>
/// <param name="stream">The stream containing the settings</param>
/// <param name="incompleteSettings">
/// Whether the settings object has any new fields in it, meaning that the configuration should be
/// overwritten.
/// </param>
/// <returns>Settings object</returns>
TSettings Read(System.IO.Stream stream, out bool incompleteSettings);
/// <summary>
/// Converts a json-formatted string into the settings object used by this configuration
/// </summary>
/// <param name="json">Json string to parse</param>
/// <param name="incompleteSettings">Whether or not the json string contained an incomplete set of settings</param>
/// <returns>Settings object</returns>
TSettings ConvertJson(string json, out bool incompleteSettings);
/// <summary>
/// Writes this configuration to a given path
/// </summary>
/// <param name="path">File location the configuration will be written to</param>
void Write(string path);
/// <summary>
/// Writes this configuration to a stream
/// </summary>
/// <param name="stream">Stream the configuration will be written to</param>
void Write(System.IO.Stream stream);
}
}