10
10
using System . Diagnostics ;
11
11
using System . Linq ;
12
12
using System . Runtime . InteropServices ;
13
+ using MessagePack . Internal ;
13
14
14
15
#pragma warning disable SA1402 // File may only contain a single type
15
16
#pragma warning disable SA1649 // File name should match first type name
16
17
17
18
namespace MessagePack . Formatters
18
19
{
20
+ [ Preserve ]
19
21
public sealed class ArrayFormatter < T > : IMessagePackFormatter < T [ ] ? >
20
22
{
21
23
public void Serialize ( ref MessagePackWriter writer , T [ ] ? value , MessagePackSerializerOptions options )
@@ -158,6 +160,7 @@ public ArraySegment<byte> Deserialize(ref MessagePackReader reader, MessagePackS
158
160
}
159
161
}
160
162
163
+ [ Preserve ]
161
164
public sealed class MemoryFormatter < T > : IMessagePackFormatter < Memory < T > >
162
165
{
163
166
public void Serialize ( ref MessagePackWriter writer , Memory < T > value , MessagePackSerializerOptions options )
@@ -172,6 +175,7 @@ public Memory<T> Deserialize(ref MessagePackReader reader, MessagePackSerializer
172
175
}
173
176
}
174
177
178
+ [ Preserve ]
175
179
public sealed class ReadOnlyMemoryFormatter < T > : IMessagePackFormatter < ReadOnlyMemory < T > >
176
180
{
177
181
public void Serialize ( ref MessagePackWriter writer , ReadOnlyMemory < T > value , MessagePackSerializerOptions options )
@@ -194,6 +198,7 @@ public ReadOnlyMemory<T> Deserialize(ref MessagePackReader reader, MessagePackSe
194
198
}
195
199
}
196
200
201
+ [ Preserve ]
197
202
public sealed class ReadOnlySequenceFormatter < T > : IMessagePackFormatter < ReadOnlySequence < T > >
198
203
{
199
204
public void Serialize ( ref MessagePackWriter writer , ReadOnlySequence < T > value , MessagePackSerializerOptions options )
@@ -218,6 +223,7 @@ public ReadOnlySequence<T> Deserialize(ref MessagePackReader reader, MessagePack
218
223
}
219
224
}
220
225
226
+ [ Preserve ]
221
227
public sealed class ArraySegmentFormatter < T > : IMessagePackFormatter < ArraySegment < T > >
222
228
{
223
229
public void Serialize ( ref MessagePackWriter writer , ArraySegment < T > value , MessagePackSerializerOptions options )
@@ -248,6 +254,7 @@ public ArraySegment<T> Deserialize(ref MessagePackReader reader, MessagePackSeri
248
254
}
249
255
250
256
// List<T> is popular format, should avoid abstraction.
257
+ [ Preserve ]
251
258
public sealed class ListFormatter < T > : IMessagePackFormatter < List < T > ? >
252
259
{
253
260
public void Serialize ( ref MessagePackWriter writer , List < T > ? value , MessagePackSerializerOptions options )
@@ -464,6 +471,7 @@ protected sealed override TCollection Complete(TCollection intermediateCollectio
464
471
}
465
472
}
466
473
474
+ [ Preserve ]
467
475
public sealed class GenericCollectionFormatter < TElement , TCollection > : CollectionFormatterBase < TElement , TCollection >
468
476
where TCollection : ICollection < TElement > , new ( )
469
477
{
@@ -478,6 +486,7 @@ protected override void Add(TCollection collection, int index, TElement value, M
478
486
}
479
487
}
480
488
489
+ [ Preserve ]
481
490
public sealed class GenericEnumerableFormatter < TElement , TCollection > : CollectionFormatterBase < TElement , TElement [ ] , TCollection >
482
491
where TCollection : IEnumerable < TElement >
483
492
{
@@ -497,6 +506,7 @@ protected override TCollection Complete(TElement[] intermediateCollection)
497
506
}
498
507
}
499
508
509
+ [ Preserve ]
500
510
public sealed class LinkedListFormatter < T > : CollectionFormatterBase < T , LinkedList < T > , LinkedList < T > . Enumerator , LinkedList < T > >
501
511
{
502
512
protected override void Add ( LinkedList < T > collection , int index , T value , MessagePackSerializerOptions options )
@@ -520,6 +530,7 @@ protected override LinkedList<T>.Enumerator GetSourceEnumerator(LinkedList<T> so
520
530
}
521
531
}
522
532
533
+ [ Preserve ]
523
534
public sealed class QueueFormatter < T > : CollectionFormatterBase < T , Queue < T > , Queue < T > . Enumerator , Queue < T > >
524
535
{
525
536
protected override int ? GetCount ( Queue < T > sequence )
@@ -640,6 +651,7 @@ public void Serialize(ref MessagePackWriter writer, PriorityQueue<TElement, TPri
640
651
#endif
641
652
642
653
// should deserialize reverse order.
654
+ [ Preserve ]
643
655
public sealed class StackFormatter < T > : CollectionFormatterBase < T , T [ ] , Stack < T > . Enumerator , Stack < T > >
644
656
{
645
657
protected override int ? GetCount ( Stack < T > sequence )
@@ -669,6 +681,7 @@ protected override Stack<T> Complete(T[] intermediateCollection)
669
681
}
670
682
}
671
683
684
+ [ Preserve ]
672
685
public sealed class HashSetFormatter < T > : CollectionFormatterBase < T , HashSet < T > , HashSet < T > . Enumerator , HashSet < T > >
673
686
{
674
687
protected override int ? GetCount ( HashSet < T > sequence )
@@ -697,6 +710,7 @@ protected override HashSet<T>.Enumerator GetSourceEnumerator(HashSet<T> source)
697
710
}
698
711
}
699
712
713
+ [ Preserve ]
700
714
public sealed class ReadOnlyCollectionFormatter < T > : CollectionFormatterBase < T , T [ ] , ReadOnlyCollection < T > >
701
715
{
702
716
protected override void Add ( T [ ] collection , int index , T value , MessagePackSerializerOptions options )
@@ -753,6 +767,7 @@ protected override ICollection<T> Complete(T[] intermediateCollection)
753
767
}
754
768
}
755
769
770
+ [ Preserve ]
756
771
public sealed class InterfaceListFormatter2 < T > : CollectionFormatterBase < T , List < T > , IList < T > >
757
772
{
758
773
protected override void Add ( List < T > collection , int index , T value , MessagePackSerializerOptions options )
@@ -771,6 +786,7 @@ protected override IList<T> Complete(List<T> intermediateCollection)
771
786
}
772
787
}
773
788
789
+ [ Preserve ]
774
790
public sealed class InterfaceCollectionFormatter2 < T > : CollectionFormatterBase < T , List < T > , ICollection < T > >
775
791
{
776
792
protected override void Add ( List < T > collection , int index , T value , MessagePackSerializerOptions options )
@@ -789,6 +805,7 @@ protected override ICollection<T> Complete(List<T> intermediateCollection)
789
805
}
790
806
}
791
807
808
+ [ Preserve ]
792
809
public sealed class InterfaceEnumerableFormatter < T > : CollectionFormatterBase < T , T [ ] , IEnumerable < T > >
793
810
{
794
811
protected override void Add ( T [ ] collection , int index , T value , MessagePackSerializerOptions options )
@@ -808,6 +825,7 @@ protected override IEnumerable<T> Complete(T[] intermediateCollection)
808
825
}
809
826
810
827
// [Key, [Array]]
828
+ [ Preserve ]
811
829
public sealed class InterfaceGroupingFormatter < TKey , TElement > : IMessagePackFormatter < IGrouping < TKey , TElement > ? >
812
830
{
813
831
public void Serialize ( ref MessagePackWriter writer , IGrouping < TKey , TElement > ? value , MessagePackSerializerOptions options )
@@ -854,6 +872,7 @@ public void Serialize(ref MessagePackWriter writer, IGrouping<TKey, TElement>? v
854
872
}
855
873
}
856
874
875
+ [ Preserve ]
857
876
public sealed class InterfaceLookupFormatter < TKey , TElement > : CollectionFormatterBase < IGrouping < TKey , TElement > , Dictionary < TKey , IGrouping < TKey , TElement > > , ILookup < TKey , TElement > >
858
877
where TKey : notnull
859
878
{
@@ -947,6 +966,7 @@ IEnumerator IEnumerable.GetEnumerator()
947
966
948
967
/* NonGenerics */
949
968
969
+ [ Preserve ]
950
970
public sealed class NonGenericListFormatter < T > : IMessagePackFormatter < T ? >
951
971
where T : class , IList , new ( )
952
972
{
@@ -998,6 +1018,7 @@ public void Serialize(ref MessagePackWriter writer, T? value, MessagePackSeriali
998
1018
}
999
1019
}
1000
1020
1021
+ [ Preserve ]
1001
1022
public sealed class NonGenericInterfaceCollectionFormatter : IMessagePackFormatter < ICollection ? >
1002
1023
{
1003
1024
public static readonly IMessagePackFormatter < ICollection ? > Instance = new NonGenericInterfaceCollectionFormatter ( ) ;
@@ -1058,6 +1079,7 @@ public void Serialize(ref MessagePackWriter writer, ICollection? value, MessageP
1058
1079
}
1059
1080
}
1060
1081
1082
+ [ Preserve ]
1061
1083
public sealed class NonGenericInterfaceEnumerableFormatter : IMessagePackFormatter < IEnumerable ? >
1062
1084
{
1063
1085
public static readonly IMessagePackFormatter < IEnumerable ? > Instance = new NonGenericInterfaceEnumerableFormatter ( ) ;
@@ -1199,6 +1221,7 @@ public void Serialize(ref MessagePackWriter writer, IList? value, MessagePackSer
1199
1221
}
1200
1222
}
1201
1223
1224
+ [ Preserve ]
1202
1225
public sealed class NonGenericDictionaryFormatter < T > : IMessagePackFormatter < T ? >
1203
1226
where T : class , IDictionary , new ( )
1204
1227
{
@@ -1312,6 +1335,7 @@ public void Serialize(ref MessagePackWriter writer, IDictionary? value, MessageP
1312
1335
}
1313
1336
}
1314
1337
1338
+ [ Preserve ]
1315
1339
public sealed class ObservableCollectionFormatter < T > : CollectionFormatterBase < T , ObservableCollection < T > >
1316
1340
{
1317
1341
protected override void Add ( ObservableCollection < T > collection , int index , T value , MessagePackSerializerOptions options )
@@ -1325,6 +1349,7 @@ protected override ObservableCollection<T> Create(int count, MessagePackSerializ
1325
1349
}
1326
1350
}
1327
1351
1352
+ [ Preserve ]
1328
1353
public sealed class ReadOnlyObservableCollectionFormatter < T > : CollectionFormatterBase < T , ObservableCollection < T > , ReadOnlyObservableCollection < T > >
1329
1354
{
1330
1355
protected override void Add ( ObservableCollection < T > collection , int index , T value , MessagePackSerializerOptions options )
@@ -1343,6 +1368,7 @@ protected override ReadOnlyObservableCollection<T> Complete(ObservableCollection
1343
1368
}
1344
1369
}
1345
1370
1371
+ [ Preserve ]
1346
1372
public sealed class InterfaceReadOnlyListFormatter < T > : CollectionFormatterBase < T , T [ ] , IReadOnlyList < T > >
1347
1373
{
1348
1374
protected override void Add ( T [ ] collection , int index , T value , MessagePackSerializerOptions options )
@@ -1361,6 +1387,7 @@ protected override IReadOnlyList<T> Complete(T[] intermediateCollection)
1361
1387
}
1362
1388
}
1363
1389
1390
+ [ Preserve ]
1364
1391
public sealed class InterfaceReadOnlyCollectionFormatter < T > : CollectionFormatterBase < T , T [ ] , IReadOnlyCollection < T > >
1365
1392
{
1366
1393
protected override void Add ( T [ ] collection , int index , T value , MessagePackSerializerOptions options )
@@ -1379,6 +1406,7 @@ protected override IReadOnlyCollection<T> Complete(T[] intermediateCollection)
1379
1406
}
1380
1407
}
1381
1408
1409
+ [ Preserve ]
1382
1410
public sealed class InterfaceSetFormatter < T > : CollectionFormatterBase < T , HashSet < T > , ISet < T > >
1383
1411
{
1384
1412
protected override void Add ( HashSet < T > collection , int index , T value , MessagePackSerializerOptions options )
@@ -1441,6 +1469,7 @@ protected override HashSet<T> Create(int count, MessagePackSerializerOptions opt
1441
1469
1442
1470
#endif
1443
1471
1472
+ [ Preserve ]
1444
1473
public sealed class ConcurrentBagFormatter < T > : CollectionFormatterBase < T , System . Collections . Concurrent . ConcurrentBag < T > >
1445
1474
{
1446
1475
protected override int ? GetCount ( ConcurrentBag < T > sequence )
@@ -1459,6 +1488,7 @@ protected override ConcurrentBag<T> Create(int count, MessagePackSerializerOptio
1459
1488
}
1460
1489
}
1461
1490
1491
+ [ Preserve ]
1462
1492
public sealed class ConcurrentQueueFormatter < T > : CollectionFormatterBase < T , System . Collections . Concurrent . ConcurrentQueue < T > >
1463
1493
{
1464
1494
protected override int ? GetCount ( ConcurrentQueue < T > sequence )
@@ -1477,6 +1507,7 @@ protected override ConcurrentQueue<T> Create(int count, MessagePackSerializerOpt
1477
1507
}
1478
1508
}
1479
1509
1510
+ [ Preserve ]
1480
1511
public sealed class ConcurrentStackFormatter < T > : CollectionFormatterBase < T , T [ ] , ConcurrentStack < T > >
1481
1512
{
1482
1513
protected override int ? GetCount ( ConcurrentStack < T > sequence )
0 commit comments