11//<auto-generated/>
22#nullable enable
3+ using System ;
4+ using System . Collections . Generic ;
35using MessagePack ;
6+ using MessagePack . Formatters ;
7+ using MessagePack . Resolvers ;
48
59namespace Devlooped
610{
@@ -20,12 +24,47 @@ partial class MessagePackDocumentSerializer : IBinaryDocumentSerializer
2024 /// <summary>
2125 /// Initializes the document serializer with the given optional serializer options.
2226 /// </summary>
23- public MessagePackDocumentSerializer ( MessagePackSerializerOptions ? options = default ) => this . options = options ;
27+ public MessagePackDocumentSerializer ( MessagePackSerializerOptions ? options = default )
28+ {
29+ this . options = options ;
30+ #if NET6_0_OR_GREATER
31+ this . options = ( options ?? MessagePackSerializerOptions . Standard )
32+ . WithResolver ( CompositeResolver . Create (
33+ StandardResolver . Instance ,
34+ DateOnlyFormatterResolver . Instance ) ) ;
35+ #endif
36+ }
2437
2538 /// <inheritdoc />
2639 public T ? Deserialize < T > ( byte [ ] data ) => data . Length == 0 ? default : MessagePackSerializer . Deserialize < T > ( data , options ) ;
2740
2841 /// <inheritdoc />
2942 public byte [ ] Serialize < T > ( T value ) => value == null ? new byte [ 0 ] : MessagePackSerializer . Serialize ( value . GetType ( ) , value , options ) ;
43+
44+ #if NET6_0_OR_GREATER
45+ class DateOnlyFormatterResolver : IFormatterResolver
46+ {
47+ public static IFormatterResolver Instance = new DateOnlyFormatterResolver ( ) ;
48+
49+ public IMessagePackFormatter < T > GetFormatter < T > ( )
50+ {
51+ if ( typeof ( T ) == typeof ( DateOnly ) )
52+ return ( IMessagePackFormatter < T > ) DateOnlyFormatter . Instance ;
53+
54+ return null ! ;
55+ }
56+
57+ class DateOnlyFormatter : IMessagePackFormatter < DateOnly >
58+ {
59+ public static readonly IMessagePackFormatter < DateOnly > Instance = new DateOnlyFormatter ( ) ;
60+
61+ public void Serialize ( ref MessagePackWriter writer , DateOnly value , MessagePackSerializerOptions options )
62+ => writer . Write ( value . DayNumber ) ;
63+
64+ public DateOnly Deserialize ( ref MessagePackReader reader , MessagePackSerializerOptions options )
65+ => DateOnly . FromDayNumber ( reader . ReadInt32 ( ) ) ;
66+ }
67+ }
68+ #endif
3069 }
3170}
0 commit comments