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 /// . /// /// /// The parent parameter to and should /// be (ideally) the the top of the serialization tree, or some other generated object in that tree, rather than some arbitrary /// object in the middle that is not managed by the generatd config system. /// /// /// Converters do not need to perform null checks, as the serializer and deserializer will do that automatically. /// /// 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); } }