forked from dotnet/runtime
/
DataContractSerializer.cs
558 lines (483 loc) · 25.2 KB
/
DataContractSerializer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.DataContracts;
using System.Text;
using System.Xml;
using DataContractDictionary = System.Collections.Generic.Dictionary<System.Xml.XmlQualifiedName, System.Runtime.Serialization.DataContracts.DataContract>;
namespace System.Runtime.Serialization
{
public sealed class DataContractSerializer : XmlObjectSerializer
{
private Type _rootType;
private DataContract? _rootContract; // post-surrogate
private bool _needsContractNsAtRoot;
private XmlDictionaryString? _rootName;
private XmlDictionaryString? _rootNamespace;
private int _maxItemsInObjectGraph;
private bool _ignoreExtensionDataObject;
private bool _preserveObjectReferences;
private ReadOnlyCollection<Type>? _knownTypeCollection;
internal IList<Type>? _knownTypeList;
internal DataContractDictionary? _knownDataContracts;
private DataContractResolver? _dataContractResolver;
private ISerializationSurrogateProvider? _serializationSurrogateProvider;
private bool _serializeReadOnlyTypes;
private static SerializationOption s_option = IsReflectionBackupAllowed() ? SerializationOption.ReflectionAsBackup : SerializationOption.CodeGenOnly;
private static bool s_optionAlreadySet;
internal sealed class SealedUTF8Encoding : UTF8Encoding
{
public SealedUTF8Encoding(bool encoderShouldEmitUTF8Identifier, bool throwOnInvalidBytes)
: base(encoderShouldEmitUTF8Identifier, throwOnInvalidBytes)
{ }
}
internal sealed class SealedUnicodeEncoding : UnicodeEncoding
{
public SealedUnicodeEncoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidBytes)
: base(bigEndian, byteOrderMark, throwOnInvalidBytes)
{ }
}
internal static SealedUTF8Encoding UTF8NoBom { get; } = new SealedUTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: false);
internal static SealedUTF8Encoding ValidatingUTF8 { get; } = new SealedUTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
internal static SealedUnicodeEncoding UTF16NoBom { get; } = new SealedUnicodeEncoding(bigEndian: false, byteOrderMark: false, throwOnInvalidBytes: false);
internal static SealedUnicodeEncoding BEUTF16NoBom { get; } = new SealedUnicodeEncoding(bigEndian: true, byteOrderMark: false, throwOnInvalidBytes: false);
internal static SealedUnicodeEncoding ValidatingUTF16 { get; } = new SealedUnicodeEncoding(bigEndian: false, byteOrderMark: false, throwOnInvalidBytes: true);
internal static SealedUnicodeEncoding ValidatingBEUTF16 { get; } = new SealedUnicodeEncoding(bigEndian: true, byteOrderMark: false, throwOnInvalidBytes: true);
internal static Base64Encoding Base64Encoding { get; } = new Base64Encoding();
internal static BinHexEncoding BinHexEncoding { get; } = new BinHexEncoding();
internal static SerializationOption Option
{
get { return RuntimeFeature.IsDynamicCodeSupported ? s_option : SerializationOption.ReflectionOnly; }
set
{
if (s_optionAlreadySet)
{
throw new InvalidOperationException(SR.CannotSetTwice);
}
s_optionAlreadySet = true;
s_option = value;
}
}
private static bool IsReflectionBackupAllowed()
{
return true;
}
public DataContractSerializer(Type type)
: this(type, (IEnumerable<Type>?)null)
{
}
public DataContractSerializer(Type type, IEnumerable<Type>? knownTypes)
: this(type, knownTypes, int.MaxValue, false, false)
{
}
public DataContractSerializer(Type type, string rootName, string rootNamespace)
: this(type, rootName, rootNamespace, null)
{
}
public DataContractSerializer(Type type, string rootName, string rootNamespace, IEnumerable<Type>? knownTypes)
: this(type, rootName, rootNamespace, knownTypes, false, false)
{
}
internal DataContractSerializer(Type type, string rootName, string rootNamespace, IEnumerable<Type>? knownTypes,
bool ignoreExtensionDataObject, bool preserveObjectReferences)
{
XmlDictionary dictionary = new XmlDictionary(2);
Initialize(type, dictionary.Add(rootName), dictionary.Add(DataContract.GetNamespace(rootNamespace)), knownTypes, int.MaxValue, ignoreExtensionDataObject, preserveObjectReferences, null, false);
}
public DataContractSerializer(Type type, XmlDictionaryString rootName, XmlDictionaryString rootNamespace)
: this(type, rootName, rootNamespace, null)
{
}
public DataContractSerializer(Type type, XmlDictionaryString rootName, XmlDictionaryString rootNamespace, IEnumerable<Type>? knownTypes)
{
Initialize(type, rootName, rootNamespace, knownTypes, int.MaxValue, false, false, null, false);
}
internal DataContractSerializer(Type type, IEnumerable<Type>? knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences)
{
Initialize(type, knownTypes, maxItemsInObjectGraph, ignoreExtensionDataObject, preserveObjectReferences, null, false);
}
public DataContractSerializer(Type type, DataContractSerializerSettings? settings)
{
settings ??= new DataContractSerializerSettings();
Initialize(type, settings.RootName, settings.RootNamespace, settings.KnownTypes, settings.MaxItemsInObjectGraph, settings.IgnoreExtensionDataObject,
settings.PreserveObjectReferences, settings.DataContractResolver, settings.SerializeReadOnlyTypes);
}
[MemberNotNull(nameof(_rootType))]
private void Initialize(Type type,
IEnumerable<Type>? knownTypes,
int maxItemsInObjectGraph,
bool ignoreExtensionDataObject,
bool preserveObjectReferences,
DataContractResolver? dataContractResolver,
bool serializeReadOnlyTypes)
{
ArgumentNullException.ThrowIfNull(type);
_rootType = type;
if (knownTypes != null)
{
_knownTypeList = new List<Type>();
foreach (Type knownType in knownTypes)
{
_knownTypeList.Add(knownType);
}
}
if (maxItemsInObjectGraph < 0)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(maxItemsInObjectGraph), SR.ValueMustBeNonNegative));
_maxItemsInObjectGraph = maxItemsInObjectGraph;
_ignoreExtensionDataObject = ignoreExtensionDataObject;
_preserveObjectReferences = preserveObjectReferences;
_dataContractResolver = dataContractResolver;
_serializeReadOnlyTypes = serializeReadOnlyTypes;
}
[MemberNotNull(nameof(_rootType))]
private void Initialize(Type type, XmlDictionaryString? rootName, XmlDictionaryString? rootNamespace,
IEnumerable<Type>? knownTypes,
int maxItemsInObjectGraph,
bool ignoreExtensionDataObject,
bool preserveObjectReferences,
DataContractResolver? dataContractResolver,
bool serializeReadOnlyTypes)
{
Initialize(type, knownTypes, maxItemsInObjectGraph, ignoreExtensionDataObject, preserveObjectReferences, dataContractResolver, serializeReadOnlyTypes);
// validate root name and namespace are both non-null
_rootName = rootName;
_rootNamespace = rootNamespace;
}
public ReadOnlyCollection<Type> KnownTypes
{
get
{
return _knownTypeCollection ??=
_knownTypeList != null ?
new ReadOnlyCollection<Type>(_knownTypeList) :
ReadOnlyCollection<Type>.Empty;
}
}
internal override DataContractDictionary? KnownDataContracts
{
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
get
{
if (_knownDataContracts == null && _knownTypeList != null)
{
// This assignment may be performed concurrently and thus is a race condition.
// It's safe, however, because at worse a new (and identical) dictionary of
// data contracts will be created and re-assigned to this field. Introduction
// of a lock here could lead to deadlocks.
_knownDataContracts = XmlObjectSerializerContext.GetDataContractsForKnownTypes(_knownTypeList);
}
return _knownDataContracts;
}
}
public int MaxItemsInObjectGraph
{
get { return _maxItemsInObjectGraph; }
}
internal ISerializationSurrogateProvider? SerializationSurrogateProvider
{
get { return _serializationSurrogateProvider; }
set { _serializationSurrogateProvider = value; }
}
public bool PreserveObjectReferences
{
get { return _preserveObjectReferences; }
}
public bool IgnoreExtensionDataObject
{
get { return _ignoreExtensionDataObject; }
}
public DataContractResolver? DataContractResolver
{
get { return _dataContractResolver; }
}
public bool SerializeReadOnlyTypes
{
get { return _serializeReadOnlyTypes; }
}
private DataContract RootContract
{
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
get
{
if (_rootContract == null)
{
_rootContract = DataContract.GetDataContract((_serializationSurrogateProvider == null) ? _rootType : GetSurrogatedType(_serializationSurrogateProvider, _rootType));
_needsContractNsAtRoot = CheckIfNeedsContractNsAtRoot(_rootName, _rootNamespace, _rootContract);
}
return _rootContract;
}
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
internal override void InternalWriteObject(XmlWriterDelegator writer, object? graph)
{
InternalWriteObject(writer, graph, null);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
internal override void InternalWriteObject(XmlWriterDelegator writer, object? graph, DataContractResolver? dataContractResolver)
{
InternalWriteStartObject(writer, graph);
InternalWriteObjectContent(writer, graph, dataContractResolver);
InternalWriteEndObject(writer);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public override void WriteObject(XmlWriter writer, object? graph)
{
WriteObjectHandleExceptions(new XmlWriterDelegator(writer), graph);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public override void WriteStartObject(XmlWriter writer, object? graph)
{
WriteStartObjectHandleExceptions(new XmlWriterDelegator(writer), graph);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public override void WriteObjectContent(XmlWriter writer, object? graph)
{
WriteObjectContentHandleExceptions(new XmlWriterDelegator(writer), graph);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public override void WriteEndObject(XmlWriter writer)
{
WriteEndObjectHandleExceptions(new XmlWriterDelegator(writer));
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public override void WriteStartObject(XmlDictionaryWriter writer, object? graph)
{
WriteStartObjectHandleExceptions(new XmlWriterDelegator(writer), graph);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public override void WriteObjectContent(XmlDictionaryWriter writer, object? graph)
{
WriteObjectContentHandleExceptions(new XmlWriterDelegator(writer), graph);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public override void WriteEndObject(XmlDictionaryWriter writer)
{
WriteEndObjectHandleExceptions(new XmlWriterDelegator(writer));
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public void WriteObject(XmlDictionaryWriter writer, object? graph, DataContractResolver? dataContractResolver)
{
WriteObjectHandleExceptions(new XmlWriterDelegator(writer), graph, dataContractResolver);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public override object? ReadObject(XmlReader reader)
{
return ReadObjectHandleExceptions(new XmlReaderDelegator(reader), true /*verifyObjectName*/);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public override object? ReadObject(XmlReader reader, bool verifyObjectName)
{
return ReadObjectHandleExceptions(new XmlReaderDelegator(reader), verifyObjectName);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public override bool IsStartObject(XmlReader reader)
{
return IsStartObjectHandleExceptions(new XmlReaderDelegator(reader));
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public override object? ReadObject(XmlDictionaryReader reader, bool verifyObjectName)
{
return ReadObjectHandleExceptions(new XmlReaderDelegator(reader), verifyObjectName);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public override bool IsStartObject(XmlDictionaryReader reader)
{
return IsStartObjectHandleExceptions(new XmlReaderDelegator(reader));
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
public object? ReadObject(XmlDictionaryReader reader, bool verifyObjectName, DataContractResolver? dataContractResolver)
{
return ReadObjectHandleExceptions(new XmlReaderDelegator(reader), verifyObjectName, dataContractResolver);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
internal override void InternalWriteStartObject(XmlWriterDelegator writer, object? graph)
{
WriteRootElement(writer, RootContract, _rootName, _rootNamespace, _needsContractNsAtRoot);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
internal override void InternalWriteObjectContent(XmlWriterDelegator writer, object? graph)
{
InternalWriteObjectContent(writer, graph, null);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
internal void InternalWriteObjectContent(XmlWriterDelegator writer, object? graph, DataContractResolver? dataContractResolver)
{
if (MaxItemsInObjectGraph == 0)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExceededMaxItemsQuota, MaxItemsInObjectGraph)));
DataContract contract = RootContract;
Type declaredType = contract.UnderlyingType;
Type graphType = (graph == null) ? declaredType : graph.GetType();
if (_serializationSurrogateProvider != null)
{
graph = SurrogateToDataContractType(_serializationSurrogateProvider, graph, declaredType, ref graphType);
}
dataContractResolver ??= DataContractResolver;
if (graph == null)
{
if (IsRootXmlAny(_rootName, contract))
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsAnyCannotBeNull, declaredType)));
WriteNull(writer);
}
else
{
if (declaredType == graphType)
{
if (contract.CanContainReferences)
{
XmlObjectSerializerWriteContext context = XmlObjectSerializerWriteContext.CreateContext(this, contract, dataContractResolver);
context.HandleGraphAtTopLevel(writer, graph, contract);
context.SerializeWithoutXsiType(contract, writer, graph, declaredType.TypeHandle);
}
else
{
contract.WriteXmlValue(writer, graph, null);
}
}
else
{
XmlObjectSerializerWriteContext? context;
if (IsRootXmlAny(_rootName, contract))
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsAnyCannotBeSerializedAsDerivedType, graphType, contract.UnderlyingType)));
contract = GetDataContract(contract, declaredType, graphType);
context = XmlObjectSerializerWriteContext.CreateContext(this, RootContract, dataContractResolver);
if (contract.CanContainReferences)
{
context.HandleGraphAtTopLevel(writer, graph, contract);
}
context.OnHandleIsReference(writer, contract, graph);
context.SerializeWithXsiTypeAtTopLevel(contract, writer, graph, declaredType.TypeHandle, graphType);
}
}
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
internal static DataContract GetDataContract(DataContract declaredTypeContract, Type declaredType, Type objectType)
{
if (declaredType.IsInterface && CollectionDataContract.IsCollectionInterface(declaredType))
{
return declaredTypeContract;
}
else if (declaredType.IsArray)//Array covariance is not supported in XSD
{
return declaredTypeContract;
}
else
{
return DataContract.GetDataContract(objectType);
}
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
internal override void InternalWriteEndObject(XmlWriterDelegator writer)
{
if (!IsRootXmlAny(_rootName, RootContract))
{
writer.WriteEndElement();
}
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
internal override object? InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName)
{
return InternalReadObject(xmlReader, verifyObjectName, null);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
internal override object? InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName, DataContractResolver? dataContractResolver)
{
if (MaxItemsInObjectGraph == 0)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExceededMaxItemsQuota, MaxItemsInObjectGraph)));
dataContractResolver ??= DataContractResolver;
if (verifyObjectName)
{
if (!InternalIsStartObject(xmlReader))
{
XmlDictionaryString? expectedName;
XmlDictionaryString? expectedNs;
if (_rootName == null)
{
expectedName = RootContract.TopLevelElementName;
expectedNs = RootContract.TopLevelElementNamespace;
}
else
{
expectedName = _rootName;
expectedNs = _rootNamespace;
}
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingElement, expectedNs, expectedName), xmlReader));
}
}
else if (!IsStartElement(xmlReader))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingElementAtDeserialize, XmlNodeType.Element), xmlReader));
}
DataContract contract = RootContract;
if (contract.IsPrimitive && object.ReferenceEquals(contract.UnderlyingType, _rootType) /*handle Nullable<T> differently*/)
{
return contract.ReadXmlValue(xmlReader, null);
}
if (IsRootXmlAny(_rootName, contract))
{
return XmlObjectSerializerReadContext.ReadRootIXmlSerializable(xmlReader, (contract as XmlDataContract)!, false /*isMemberType*/);
}
XmlObjectSerializerReadContext context = XmlObjectSerializerReadContext.CreateContext(this, contract, dataContractResolver);
return context.InternalDeserialize(xmlReader, _rootType, contract, null, null);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
internal override bool InternalIsStartObject(XmlReaderDelegator reader)
{
return IsRootElement(reader, RootContract, _rootName, _rootNamespace);
}
internal override Type? GetSerializeType(object? graph)
{
return (graph == null) ? _rootType : graph.GetType();
}
internal override Type? GetDeserializeType()
{
return _rootType;
}
[return: NotNullIfNotNull(nameof(oldObj))]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
internal static object? SurrogateToDataContractType(ISerializationSurrogateProvider serializationSurrogateProvider, object? oldObj, Type surrogatedDeclaredType, ref Type objType)
{
object? obj = DataContractSurrogateCaller.GetObjectToSerialize(serializationSurrogateProvider, oldObj, objType, surrogatedDeclaredType);
if (obj != oldObj)
{
objType = obj != null ? obj.GetType() : Globals.TypeOfObject;
}
return obj;
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
internal static Type GetSurrogatedType(ISerializationSurrogateProvider serializationSurrogateProvider, Type type)
{
return DataContractSurrogateCaller.GetDataContractType(serializationSurrogateProvider, DataContract.UnwrapNullableType(type));
}
}
}