Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DataContractSerializer.cs
Go to the documentation of this file.
5using System.Xml;
6
8
10{
11 private Type _rootType;
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
41 private static bool _optionAlreadySet;
42
44 {
45 get
46 {
48 {
49 return SerializationOption.ReflectionOnly;
50 }
51 return _option;
52 }
53 set
54 {
56 {
58 }
59 _optionAlreadySet = true;
60 _option = value;
61 }
62 }
63
65 {
66 get
67 {
68 if (_knownTypeCollection == null)
69 {
70 if (knownTypeList != null)
71 {
73 }
74 else
75 {
77 }
78 }
80 }
81 }
82
84 {
85 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
86 get
87 {
88 if (knownDataContracts == null && knownTypeList != null)
89 {
91 }
92 return knownDataContracts;
93 }
94 }
95
97
109
111
113
115
117
119 {
120 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
121 get
122 {
123 if (_rootContract == null)
124 {
127 }
128 return _rootContract;
129 }
130 }
131
132 private static bool IsReflectionBackupAllowed()
133 {
134 return true;
135 }
136
141
143 {
144 Initialize(type, knownTypes, int.MaxValue, ignoreExtensionDataObject: false, preserveObjectReferences: false, null, serializeReadOnlyTypes: false);
145 }
146
151
153 {
155 Initialize(type, xmlDictionary.Add(rootName), xmlDictionary.Add(DataContract.GetNamespace(rootNamespace)), knownTypes, int.MaxValue, ignoreExtensionDataObject: false, preserveObjectReferences: false, null, serializeReadOnlyTypes: false);
156 }
157
162
164 {
165 Initialize(type, rootName, rootNamespace, knownTypes, int.MaxValue, ignoreExtensionDataObject: false, preserveObjectReferences: false, null, serializeReadOnlyTypes: false);
166 }
167
169 {
170 Initialize(type, knownTypes, maxItemsInObjectGraph, ignoreExtensionDataObject, preserveObjectReferences, null, serializeReadOnlyTypes: false);
171 }
172
174 {
175 if (settings == null)
176 {
177 settings = new DataContractSerializerSettings();
178 }
180 }
181
182 [MemberNotNull("_rootType")]
183 private void Initialize(Type type, IEnumerable<Type> knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, DataContractResolver dataContractResolver, bool serializeReadOnlyTypes)
184 {
186 _rootType = type;
187 if (knownTypes != null)
188 {
190 foreach (Type knownType in knownTypes)
191 {
193 }
194 }
195 if (maxItemsInObjectGraph < 0)
196 {
198 }
201 _preserveObjectReferences = preserveObjectReferences;
203 _serializeReadOnlyTypes = serializeReadOnlyTypes;
204 }
205
206 [MemberNotNull("_rootType")]
213
214 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
215 internal override void InternalWriteObject(XmlWriterDelegator writer, object graph)
216 {
218 }
219
220 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
227
228 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
229 public override void WriteObject(XmlWriter writer, object? graph)
230 {
232 }
233
234 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
239
240 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
245
246 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
251
252 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
257
258 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
263
264 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
269
270 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
275
276 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
277 public override object? ReadObject(XmlReader reader)
278 {
280 }
281
282 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
283 public override object? ReadObject(XmlReader reader, bool verifyObjectName)
284 {
286 }
287
288 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
289 public override bool IsStartObject(XmlReader reader)
290 {
292 }
293
294 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
295 public override object? ReadObject(XmlDictionaryReader reader, bool verifyObjectName)
296 {
298 }
299
300 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
301 public override bool IsStartObject(XmlDictionaryReader reader)
302 {
304 }
305
306 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
311
312 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
317
318 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
320 {
322 }
323
324 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
326 {
327 if (MaxItemsInObjectGraph == 0)
328 {
330 }
332 Type underlyingType = rootContract.UnderlyingType;
333 Type objType = ((graph == null) ? underlyingType : graph.GetType());
335 {
337 }
338 if (dataContractResolver == null)
339 {
341 }
342 if (graph == null)
343 {
345 {
347 }
349 return;
350 }
351 if (underlyingType == objType)
352 {
353 if (rootContract.CanContainReferences)
354 {
357 xmlObjectSerializerWriteContext.SerializeWithoutXsiType(rootContract, writer, graph, underlyingType.TypeHandle);
358 }
359 else
360 {
361 rootContract.WriteXmlValue(writer, graph, null);
362 }
363 return;
364 }
367 {
369 }
372 if (rootContract.CanContainReferences)
373 {
375 }
377 xmlObjectSerializerWriteContext2.SerializeWithXsiTypeAtTopLevel(rootContract, writer, graph, underlyingType.TypeHandle, objType);
378 }
379
380 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
393
394 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
396 {
398 {
399 writer.WriteEndElement();
400 }
401 }
402
403 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
405 {
407 }
408
409 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
411 {
412 if (MaxItemsInObjectGraph == 0)
413 {
415 }
416 if (dataContractResolver == null)
417 {
419 }
421 {
423 {
426 if (_rootName == null)
427 {
430 }
431 else
432 {
433 p = _rootName;
435 }
437 }
438 }
439 else if (!IsStartElement(xmlReader))
440 {
442 }
444 if (rootContract.IsPrimitive && (object)rootContract.UnderlyingType == _rootType)
445 {
446 return rootContract.ReadXmlValue(xmlReader, null);
447 }
449 {
451 }
453 return xmlObjectSerializerReadContext.InternalDeserialize(xmlReader, _rootType, rootContract, null, null);
454 }
455
456 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
457 internal override bool InternalIsStartObject(XmlReaderDelegator reader)
458 {
460 }
461
462 internal override Type GetSerializeType(object graph)
463 {
464 if (graph != null)
465 {
466 return graph.GetType();
467 }
468 return _rootType;
469 }
470
471 internal override Type GetDeserializeType()
472 {
473 return _rootType;
474 }
475
476 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
477 [return: NotNullIfNotNull("oldObj")]
487
488 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
493}
void Add(TKey key, TValue value)
override void WriteEndObject(XmlDictionaryWriter writer)
DataContractSerializer(Type type, DataContractSerializerSettings? settings)
override void WriteStartObject(XmlWriter writer, object? graph)
Dictionary< XmlQualifiedName, DataContract > knownDataContracts
override bool InternalIsStartObject(XmlReaderDelegator reader)
override void WriteStartObject(XmlDictionaryWriter writer, object? graph)
static object SurrogateToDataContractType(ISerializationSurrogateProvider serializationSurrogateProvider, object oldObj, Type surrogatedDeclaredType, ref Type objType)
override void InternalWriteEndObject(XmlWriterDelegator writer)
override object InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName)
DataContractSerializer(Type type, IEnumerable< Type > knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences)
DataContractSerializer(Type type, IEnumerable< Type >? knownTypes)
override void WriteObjectContent(XmlDictionaryWriter writer, object? graph)
object? ReadObject(XmlDictionaryReader reader, bool verifyObjectName, DataContractResolver? dataContractResolver)
static DataContract GetDataContract(DataContract declaredTypeContract, Type declaredType, Type objectType)
override void InternalWriteObjectContent(XmlWriterDelegator writer, object graph)
DataContractSerializer(Type type, XmlDictionaryString rootName, XmlDictionaryString rootNamespace)
void Initialize(Type type, XmlDictionaryString rootName, XmlDictionaryString rootNamespace, IEnumerable< Type > knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, DataContractResolver dataContractResolver, bool serializeReadOnlyTypes)
void InternalWriteObjectContent(XmlWriterDelegator writer, object graph, DataContractResolver dataContractResolver)
override bool IsStartObject(XmlDictionaryReader reader)
override? object ReadObject(XmlReader reader, bool verifyObjectName)
void Initialize(Type type, IEnumerable< Type > knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, DataContractResolver dataContractResolver, bool serializeReadOnlyTypes)
ISerializationSurrogateProvider _serializationSurrogateProvider
override void WriteObjectContent(XmlWriter writer, object? graph)
override void InternalWriteStartObject(XmlWriterDelegator writer, object graph)
DataContractSerializer(Type type, string rootName, string rootNamespace, IEnumerable< Type >? knownTypes)
override? Dictionary< XmlQualifiedName, DataContract > KnownDataContracts
void WriteObject(XmlDictionaryWriter writer, object? graph, DataContractResolver? dataContractResolver)
ISerializationSurrogateProvider? SerializationSurrogateProvider
DataContractSerializer(Type type, string rootName, string rootNamespace)
override void InternalWriteObject(XmlWriterDelegator writer, object graph, DataContractResolver dataContractResolver)
override object InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName, DataContractResolver dataContractResolver)
static Type GetSurrogatedType(ISerializationSurrogateProvider serializationSurrogateProvider, Type type)
override? object ReadObject(XmlDictionaryReader reader, bool verifyObjectName)
override void WriteObject(XmlWriter writer, object? graph)
DataContractSerializer(Type type, XmlDictionaryString rootName, XmlDictionaryString rootNamespace, IEnumerable< Type >? knownTypes)
override void InternalWriteObject(XmlWriterDelegator writer, object graph)
static Type GetDataContractType(ISerializationSurrogateProvider surrogateProvider, Type type)
static object GetObjectToSerialize(ISerializationSurrogateProvider surrogateProvider, object obj, Type objType, Type membertype)
static DataContract GetDataContract(Type type)
virtual XmlDictionaryString TopLevelElementNamespace
virtual XmlDictionaryString TopLevelElementName
static Dictionary< XmlQualifiedName, DataContract > GetDataContractsForKnownTypes(IList< Type > knownTypeList)
static XmlObjectSerializerReadContext CreateContext(DataContractSerializer serializer, DataContract rootTypeDataContract, DataContractResolver dataContractResolver)
static object ReadRootIXmlSerializable(XmlReaderDelegator xmlReader, XmlDataContract xmlDataContract, bool isMemberType)
static XmlObjectSerializerWriteContext CreateContext(DataContractSerializer serializer, DataContract rootTypeDataContract, DataContractResolver dataContractResolver)
bool IsStartObjectHandleExceptions(XmlReaderDelegator reader)
bool CheckIfNeedsContractNsAtRoot(XmlDictionaryString name, XmlDictionaryString ns, DataContract contract)
static Exception CreateSerializationExceptionWithReaderDetails(string errorMessage, XmlReaderDelegator reader)
void WriteEndObjectHandleExceptions(XmlWriterDelegator writer)
bool IsRootXmlAny(XmlDictionaryString rootName, DataContract contract)
static void WriteNull(XmlWriterDelegator writer)
static SerializationException CreateSerializationException(string errorMessage)
void WriteObjectHandleExceptions(XmlWriterDelegator writer, object graph)
void WriteRootElement(XmlWriterDelegator writer, DataContract contract, XmlDictionaryString name, XmlDictionaryString ns, bool needsContractNsAtRoot)
static void CheckNull(object obj, string name)
object ReadObjectHandleExceptions(XmlReaderDelegator reader, bool verifyObjectName)
void WriteStartObjectHandleExceptions(XmlWriterDelegator writer, object graph)
void WriteObjectContentHandleExceptions(XmlWriterDelegator writer, object graph)
bool IsRootElement(XmlReaderDelegator reader, DataContract contract, XmlDictionaryString name, XmlDictionaryString ns)
static string IsAnyCannotBeSerializedAsDerivedType
Definition SR.cs:172
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string ValueMustBeNonNegative
Definition SR.cs:296
static string ExceededMaxItemsQuota
Definition SR.cs:102
static string ExpectingElementAtDeserialize
Definition SR.cs:106
static string ExpectingElement
Definition SR.cs:104
static string CannotSetTwice
Definition SR.cs:708
static string IsAnyCannotBeNull
Definition SR.cs:170
Definition SR.cs:7
static readonly Type[] EmptyTypes
Definition Type.cs:19