using System;
using System.IO;
using System.Threading.Tasks;
using IPA.Config.Data;
namespace IPA.Config
{
///
/// An interface for configuration providers.
///
///
///
/// Implementers must provide a default constructor. Do not assume that will ever be set for a given object.
///
///
/// Implementers are expected to preserve the typing of values passed to when returned from .
/// The only exceptions to this are the numeric types, and , since they can be coerced
/// to each other with and respectively. The provider should
/// however store and recover with as much precision as is possible. For example, a JSON provider may decide to
/// decode all numbers that have an integral value, even if they were originally , as .
/// This is reasonable, as is more precise, particularly with larger values, than .
///
///
public interface IConfigProvider
{
///
/// Gets the extension without a dot to use for files handled by this provider.
///
///
/// This must work immediately, and is used to generate the used to set
/// .
///
string Extension { get; }
///
/// Stores the given to disk in the format specified.
///
/// the to store
/// the file to write to
void Store(Value value, FileInfo file);
///
/// Loads a from disk in whatever format this provider provides
/// and returns it.
///
/// the file to read from
/// the loaded
Value Load(FileInfo file);
}
///
/// A wrapper for an and the to use with it.
///
public class ConfigProvider // this *should* be a struct imo, but mono doesn't seem to like that
{
private readonly FileInfo file;
private readonly IConfigProvider provider;
internal ConfigProvider(FileInfo file, IConfigProvider provider)
{
this.file = file; this.provider = provider;
}
///
/// Stores the given to disk in the format specified.
///
/// the to store
public void Store(Value value) => provider.Store(value, file);
///
/// Loads a from disk in whatever format this provider provides
/// and returns it.
///
/// the loaded
public Value Load() => provider.Load(file);
}
}