using QFSW.QC.Utilities; using System; namespace QFSW.QC { /// /// Serializer for all types that are generic constructions of a single type. /// public abstract class GenericQcSerializer : IQcSerializer { /// /// The incomplete generic type of this serializer. /// protected abstract Type GenericType { get; } private Func _recursiveSerializer; protected GenericQcSerializer() { if (!GenericType.IsGenericType) { throw new ArgumentException($"Generic Serializers must use a generic type as their base"); } if (GenericType.IsConstructedGenericType) { throw new ArgumentException($"Generic Serializers must use an incomplete generic type as their base"); } } public virtual int Priority => -500; public bool CanSerialize(Type type) { return type.IsGenericTypeOf(GenericType); } string IQcSerializer.SerializeFormatted(object value, QuantumTheme theme, Func recursiveSerializer) { _recursiveSerializer = recursiveSerializer; return SerializeFormatted(value, theme); } protected string SerializeRecursive(object value, QuantumTheme theme) { return _recursiveSerializer(value, theme); } public abstract string SerializeFormatted(object value, QuantumTheme theme); } }