using IPA.Config.Data;
using System;
namespace IPA.Config.Stores
{
///
/// The base interface for a value converter for use by objects generated by
/// .
///
///
/// The object returned from , if fed into ,
/// should return equivalent structures. Similarly, if the result of
/// is fed into , the resulting object should be equivalent to the one passed to
/// .
///
public interface IValueConverter
{
///
/// Converts the given object to a .
///
/// the object to convert
/// the owning object of
/// a representation of as a structure
Value ToValue(object obj, object parent);
///
/// Converts the given to the object type handled by this converter.
///
/// the to deserialize
/// the object that will own the result
/// the deserialized object
object FromValue(Value value, object parent);
///
/// Gets the type that this handles.
///
Type Type { get; }
}
///
/// A strongly-typed .
///
/// the type of object to handle
///
public abstract class ValueConverter : IValueConverter
{
///
/// Converts the given object to a .
///
/// the object to convert
/// the owning object of
/// a representation of as a structure
///
public abstract Value ToValue(T obj, object parent);
///
/// Converts the given to the object type handled by this converter.
///
/// the to deserialize
/// the object that will own the result
/// the deserialized object
///
public abstract T FromValue(Value value, object parent);
Value IValueConverter.ToValue(object obj, object parent) => ToValue((T)obj, parent);
object IValueConverter.FromValue(Value value, object parent) => FromValue(value, parent);
Type IValueConverter.Type => typeof(T);
}
}