Open blairconrad opened 4 years ago
@CableZa and friends, I have a proof-of-concept of serializing a Lazy<int>
(because it was easy and available on all platforms) that I think I can expand to support Task
and pretty much anything we want, for all serializers. I'm going to assign this issue to myself.
Sketch of my plan: to implement type converters that will transform an unserializable type into a serializable representation, before we hit the serializer, and likewise to convert back. Rough and provisional interface for such a converter:
interface ITypeConverter
{
/// <summary>
/// Potentially converts an unserializable object to a more serializable form.
/// </summary>
/// <param name="input">An input object.</param>
/// <param name="output">An output object. Will be assigned to a simpler representation of <paramref name="input"/>, if this converter knows how.</param>
/// <returns><c>true</c> if the conversion happened, otherwise <c>false</c>. Good for building a chain of responsibility.</returns>
bool ConvertForSerialization(object? input, out object? output);
/// <summary>
/// Potentially converts the serializable form of an object back to its unserializable form.
/// </summary>
/// <param name="deserializedType">The desired deserialized type.</param>
/// <param name="input">An input object.</param>
/// <param name="output">An output object. Will be reconstituted from it's simpler representation as <paramref name="input"/>, if this converter knows how.</param>
/// <returns><c>true</c> if the conversion happened, otherwise <c>false</c>. Good for building a chain of responsibility.</returns>
bool ConvertForDeserialization(Type deserializedType, object? input, out object? output);
}
That'll probably change a bit as I work. My initial plan is to build in a few converters for some framework types, and allow a plugin mechanism for clients to add their own.
Split from #79, as proposed by @CableZa.