dahomey-technologies/Dahomey.Cbor

Support `struct` types

ChristophLindemann opened this issue · 0 comments

Currently struct and readonly struct can not be serialized/deserialized without writing a specific converter.

The ObjectConverter class is constrained to where T : class. So even if you write you own generic struct converter, deserialization does not work with the DiscriminatorConvention as it expects to get an IObjectConverter<T>:

if (_discriminatorConvention != null)
{
CborReaderBookmark bookmark = reader.GetBookmark();
if (FindItem(ref reader, _discriminatorConvention.MemberName))
{
// discriminator value
Type actualType = _discriminatorConvention.ReadDiscriminator(ref reader);
context.converter = (IObjectConverter<T>)_registry.ConverterRegistry.Lookup(actualType);
}
else
{
context.converter = this;
}

But IObjectConverter<T> is restricted to class

public interface IObjectConverter<out T> : IObjectConverter
where T : class