Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DataContractJsonSerializer.cs
Go to the documentation of this file.
4using System.IO;
5using System.Text;
6using System.Xml;
7
9
11{
13
15
17
19
21
23
25
27
29
31
33
35
36 private Type _rootType;
37
39
41 {
42 get
43 {
44 if (_knownTypeCollection == null)
45 {
46 if (knownTypeList != null)
47 {
49 }
50 else
51 {
53 }
54 }
56 }
57 }
58
60 {
61 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
62 get
63 {
64 if (knownDataContracts == null && knownTypeList != null)
65 {
67 }
68 return knownDataContracts;
69 }
70 }
71
73
75
77
79
81
83 {
84 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
85 get
86 {
87 if (_rootContract == null)
88 {
91 }
92 return _rootContract;
93 }
94 }
95
97
98 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
103
104 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
107 {
108 }
109
110 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
115
116 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
121
122 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
131
132 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
137
138 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
140 {
141 if (settings == null)
142 {
143 settings = new DataContractJsonSerializerSettings();
144 }
145 Initialize(type, (settings.RootName == null) ? null : new XmlDictionary(1).Add(settings.RootName), settings.KnownTypes, settings.MaxItemsInObjectGraph, settings.IgnoreExtensionDataObject, settings.EmitTypeInformation, settings.SerializeReadOnlyTypes, settings.DateTimeFormat, settings.UseSimpleDictionaryFormat);
146 }
147
148 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
153
154 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
155 public override bool IsStartObject(XmlReader reader)
156 {
158 }
159
160 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
161 public override bool IsStartObject(XmlDictionaryReader reader)
162 {
164 }
165
166 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
172
173 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
174 public override object? ReadObject(XmlReader reader)
175 {
177 }
178
179 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
180 public override object? ReadObject(XmlReader reader, bool verifyObjectName)
181 {
183 }
184
185 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
186 public override object? ReadObject(XmlDictionaryReader reader)
187 {
189 }
190
191 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
192 public override object? ReadObject(XmlDictionaryReader reader, bool verifyObjectName)
193 {
195 }
196
197 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
202
203 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
208
209 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
217
218 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
223
224 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
229
230 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
235
236 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
241
242 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
247
248 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
253
254 internal static bool CheckIfJsonNameRequiresMapping(string jsonName)
255 {
256 if (jsonName != null)
257 {
259 {
260 return true;
261 }
262 for (int i = 0; i < jsonName.Length; i++)
263 {
265 {
266 return true;
267 }
268 }
269 }
270 return false;
271 }
272
274 {
275 if (jsonName != null)
276 {
278 }
279 return false;
280 }
281
282 internal static bool CheckIfXmlNameRequiresMapping(string xmlName)
283 {
284 if (xmlName != null)
285 {
287 }
288 return false;
289 }
290
292 {
293 if (xmlName != null)
294 {
296 }
297 return false;
298 }
299
300 internal static string ConvertXmlNameToJsonName(string xmlName)
301 {
303 }
304
305 [return: NotNullIfNotNull("xmlName")]
307 {
308 if (xmlName != null)
309 {
311 }
312 return null;
313 }
314
315 internal static bool IsJsonLocalName(XmlReaderDelegator reader, string elementName)
316 {
318 {
319 return elementName == name;
320 }
321 return false;
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 return JsonDataContract.GetJsonDataContract(contract).ReadJsonValue(reader, context);
328 }
329
331 {
332 writer.WriteAttributeString(null, "type", null, "null");
333 }
334
335 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
340
341 internal override Type GetDeserializeType()
342 {
343 return _rootType;
344 }
345
346 internal override Type GetSerializeType(object graph)
347 {
348 if (graph != null)
349 {
350 return graph.GetType();
351 }
352 return _rootType;
353 }
354
355 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
356 internal override bool InternalIsStartObject(XmlReaderDelegator reader)
357 {
359 {
360 return true;
361 }
362 return IsJsonLocalName(reader, RootName.Value);
363 }
364
365 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
391
392 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
394 {
395 writer.WriteEndElement();
396 }
397
398 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
405
406 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
408 {
409 if (MaxItemsInObjectGraph == 0)
410 {
412 }
414 Type underlyingType = rootContract.UnderlyingType;
415 Type type = ((graph == null) ? underlyingType : graph.GetType());
416 if (graph == null)
417 {
419 return;
420 }
421 if (underlyingType == type)
422 {
423 if (rootContract.CanContainReferences)
424 {
428 }
429 else
430 {
432 }
433 return;
434 }
437 if (rootContract.CanContainReferences)
438 {
440 xmlObjectSerializerWriteContextComplexJson2.SerializeWithXsiTypeAtTopLevel(rootContract, writer, graph, underlyingType.TypeHandle, type);
441 }
442 else
443 {
445 }
446 }
447
448 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
450 {
452 {
453 writer.WriteStartElement("a", "item", "item");
454 writer.WriteAttributeString(null, "item", null, RootName.Value);
455 }
456 else
457 {
458 writer.WriteStartElement(RootName, XmlDictionaryString.Empty);
459 }
460 }
461
462 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
464 {
468 {
469 if (itemType.IsGenericType && itemType.GetGenericTypeDefinition() == Globals.TypeOfKeyValue)
470 {
471 itemType = Globals.TypeOfKeyValuePair.MakeGenericType(itemType.GenericTypeArguments);
472 }
474 type = itemType;
475 }
476 }
477
478 [MemberNotNull("_rootType")]
479 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
507
508 [MemberNotNull("_rootType")]
509 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
516
524
525 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
532}
void Add(TKey key, TValue value)
static DataContract GetDataContract(DataContract declaredTypeContract, Type declaredType, Type objectType)
static string GetClrTypeFullName(Type type)
static DataContract GetDataContract(Type type)
DataContractJsonSerializer(Type type, XmlDictionaryString rootName, IEnumerable< Type > knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool alwaysEmitTypeInformation)
override? object ReadObject(XmlDictionaryReader reader, bool verifyObjectName)
override void InternalWriteObject(XmlWriterDelegator writer, object graph)
override void WriteStartObject(XmlDictionaryWriter writer, object? graph)
void Initialize(Type type, XmlDictionaryString rootName, IEnumerable< Type > knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, EmitTypeInformation emitTypeInformation, bool serializeReadOnlyTypes, DateTimeFormat dateTimeFormat, bool useSimpleDictionaryFormat)
override void WriteObject(XmlDictionaryWriter writer, object? graph)
Dictionary< XmlQualifiedName, DataContract > knownDataContracts
override void WriteObjectContent(XmlWriter writer, object? graph)
static bool CheckIfJsonNameRequiresMapping(XmlDictionaryString jsonName)
DataContractJsonSerializer(Type type, XmlDictionaryString? rootName, IEnumerable< Type >? knownTypes)
override? Dictionary< XmlQualifiedName, DataContract > KnownDataContracts
static bool IsJsonLocalName(XmlReaderDelegator reader, string elementName)
override void InternalWriteObjectContent(XmlWriterDelegator writer, object graph)
DataContractJsonSerializer(Type type, string? rootName, IEnumerable< Type >? knownTypes)
override object InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName)
static XmlDictionaryString ConvertXmlNameToJsonName(XmlDictionaryString xmlName)
static void WriteJsonValue(JsonDataContract contract, XmlWriterDelegator writer, object graph, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle)
void Initialize(Type type, IEnumerable< Type > knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, EmitTypeInformation emitTypeInformation, bool serializeReadOnlyTypes, DateTimeFormat dateTimeFormat, bool useSimpleDictionaryFormat)
DataContractJsonSerializer(Type type, IEnumerable< Type >? knownTypes)
override void WriteObjectContent(XmlDictionaryWriter writer, object? graph)
override void WriteStartObject(XmlWriter writer, object? graph)
override? object ReadObject(XmlReader reader, bool verifyObjectName)
DataContractJsonSerializer(Type type, DataContractJsonSerializerSettings? settings)
static object ReadJsonValue(DataContract contract, XmlReaderDelegator reader, XmlObjectSerializerReadContextComplexJson context)
override void InternalWriteStartObject(XmlWriterDelegator writer, object graph)
static DataContract GetDataContract(DataContract declaredTypeContract, Type declaredType, Type objectType)
static JsonDataContract GetJsonDataContract(DataContract traditionalDataContract)
static readonly XmlDictionaryString rootDictionaryString
static XmlDictionaryWriter CreateJsonWriter(Stream stream)
static XmlDictionaryReader CreateJsonReader(Stream stream, XmlDictionaryReaderQuotas quotas)
static bool TryGetJsonLocalName(XmlReaderDelegator xmlReader, [NotNullWhen(true)] out string name)
static XmlObjectSerializerReadContextComplexJson CreateContext(DataContractJsonSerializer serializer, DataContract rootTypeDataContract)
static XmlObjectSerializerWriteContextComplexJson CreateContext(DataContractJsonSerializer serializer, DataContract rootTypeDataContract)
static Dictionary< XmlQualifiedName, DataContract > GetDataContractsForKnownTypes(IList< Type > knownTypeList)
bool IsStartObjectHandleExceptions(XmlReaderDelegator reader)
static Exception CreateSerializationExceptionWithReaderDetails(string errorMessage, XmlReaderDelegator reader)
void WriteEndObjectHandleExceptions(XmlWriterDelegator writer)
static SerializationException CreateSerializationException(string errorMessage)
void WriteObjectHandleExceptions(XmlWriterDelegator writer, object graph)
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 JsonUnsupportedForIsReference
Definition SR.cs:522
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
Definition SR.cs:7
static Encoding UTF8
Definition Encoding.cs:526
static readonly Type[] EmptyTypes
Definition Type.cs:19
static ? string DecodeName(string? name)
Definition XmlConvert.cs:55
static XmlDictionaryString Empty
virtual XmlDictionaryString Add(string value)