Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlObjectSerializer.cs
Go to the documentation of this file.
4using System.IO;
6using System.Text;
7using System.Xml;
8
10
11public abstract class XmlObjectSerializer
12{
14
16 {
17 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
18 get
19 {
20 return null;
21 }
22 }
23
25 {
26 get
27 {
28 if (s_formatterConverter == null)
29 {
31 }
33 }
34 }
35
36 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
37 public abstract void WriteStartObject(XmlDictionaryWriter writer, object? graph);
38
39 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
40 public abstract void WriteObjectContent(XmlDictionaryWriter writer, object? graph);
41
42 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
44
45 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
53
54 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
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.")]
67
68 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
74
75 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
81
82 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
87
88 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
93
94 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
111
112 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
113 internal virtual void InternalWriteObject(XmlWriterDelegator writer, object graph)
114 {
117 WriteEndObject(writer.Writer);
118 }
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.")]
125
126 [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.")]
143
144 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
161
162 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
183
184 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
201
203 {
204 if (name == null)
205 {
206 if (contract.HasRoot)
207 {
208 contract.WriteRootElement(writer, contract.TopLevelElementName, contract.TopLevelElementNamespace);
209 }
210 return;
211 }
212 contract.WriteRootElement(writer, name, ns);
214 {
215 writer.WriteNamespaceDecl(contract.Namespace);
216 }
217 }
218
220 {
221 if (name == null)
222 {
223 return false;
224 }
225 if (contract.IsBuiltInDataContract || !contract.CanContainReferences)
226 {
227 return false;
228 }
229 string @string = XmlDictionaryString.GetString(contract.Namespace);
230 if (string.IsNullOrEmpty(@string) || @string == XmlDictionaryString.GetString(ns))
231 {
232 return false;
233 }
234 return true;
235 }
236
237 internal static void WriteNull(XmlWriterDelegator writer)
238 {
240 }
241
243 {
244 if (contract.Name != declaredContract.Name || contract.Namespace != declaredContract.Namespace)
245 {
246 if (contract.Name.Value == declaredContract.Name.Value)
247 {
248 return contract.Namespace.Value == declaredContract.Namespace.Value;
249 }
250 return false;
251 }
252 return true;
253 }
254
255 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
261
262 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
263 public virtual object? ReadObject(XmlReader reader)
264 {
265 CheckNull(reader, "reader");
267 }
268
269 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
270 public virtual object? ReadObject(XmlDictionaryReader reader)
271 {
273 }
274
275 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
276 public virtual object? ReadObject(XmlReader reader, bool verifyObjectName)
277 {
278 CheckNull(reader, "reader");
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 abstract object? ReadObject(XmlDictionaryReader reader, bool verifyObjectName);
284
285 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
286 public virtual bool IsStartObject(XmlReader reader)
287 {
288 CheckNull(reader, "reader");
290 }
291
292 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
293 public abstract bool IsStartObject(XmlDictionaryReader reader);
294
295 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
296 internal virtual object InternalReadObject(XmlReaderDelegator reader, bool verifyObjectName)
297 {
299 }
300
301 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
306
307 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
312
313 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
315 {
316 return ReadObjectHandleExceptions(reader, verifyObjectName, null);
317 }
318
319 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
336
337 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
354
356 {
357 if (rootName == null)
358 {
359 return !contract.HasRoot;
360 }
361 return false;
362 }
363
364 internal bool IsStartElement(XmlReaderDelegator reader)
365 {
366 if (!reader.MoveToElement())
367 {
368 return reader.IsStartElement();
369 }
370 return true;
371 }
372
373 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
375 {
376 reader.MoveToElement();
377 if (name != null)
378 {
379 return reader.IsStartElement(name, ns ?? XmlDictionaryString.Empty);
380 }
381 if (!contract.HasRoot)
382 {
383 return reader.IsStartElement();
384 }
385 if (reader.IsStartElement(contract.TopLevelElementName, contract.TopLevelElementNamespace))
386 {
387 return true;
388 }
390 if (classDataContract != null)
391 {
393 }
394 while (classDataContract != null)
395 {
396 if (reader.IsStartElement(classDataContract.TopLevelElementName, classDataContract.TopLevelElementNamespace))
397 {
398 return true;
399 }
401 }
402 if (classDataContract == null)
403 {
405 if (reader.IsStartElement(primitiveDataContract.TopLevelElementName, primitiveDataContract.TopLevelElementNamespace))
406 {
407 return true;
408 }
409 }
410 return false;
411 }
412
413 internal static void CheckNull(object obj, string name)
414 {
415 if (obj == null)
416 {
418 }
419 }
420
421 internal static string TryAddLineInfo(XmlReaderDelegator reader, string errorMessage)
422 {
423 if (reader.HasLineInfo())
424 {
428 handler.AppendLiteral(" ");
430 return string.Create(invariantCulture, ref handler);
431 }
432 return errorMessage;
433 }
434
439
444
445 [MethodImpl(MethodImplOptions.NoInlining)]
450
452 {
453 string p = ((type == null) ? string.Empty : System.SR.Format(System.SR.ErrorTypeInfo, DataContract.GetClrTypeFullName(type)));
454 string p2 = ((innerException == null) ? string.Empty : innerException.Message);
455 return System.SR.Format(errorMessage, p, p2);
456 }
457
458 internal virtual Type GetSerializeType(object graph)
459 {
460 return graph?.GetType();
461 }
462
463 internal virtual Type GetDeserializeType()
464 {
465 return null;
466 }
467}
static CultureInfo InvariantCulture
static string GetClrTypeFullName(Type type)
static readonly XmlDictionaryString XsiNilLocalName
static readonly XmlDictionaryString SchemaInstanceNamespace
static PrimitiveDataContract GetPrimitiveDataContract(Type type)
virtual object InternalReadObject(XmlReaderDelegator reader, bool verifyObjectName, DataContractResolver dataContractResolver)
virtual void InternalWriteObject(XmlWriterDelegator writer, object graph, DataContractResolver dataContractResolver)
void WriteStartObject(XmlDictionaryWriter writer, object? graph)
virtual bool InternalIsStartObject(XmlReaderDelegator reader)
bool IsStartObjectHandleExceptions(XmlReaderDelegator reader)
virtual void InternalWriteEndObject(XmlWriterDelegator writer)
virtual object InternalReadObject(XmlReaderDelegator reader, bool verifyObjectName)
bool CheckIfNeedsContractNsAtRoot(XmlDictionaryString name, XmlDictionaryString ns, DataContract contract)
static Exception CreateSerializationExceptionWithReaderDetails(string errorMessage, XmlReaderDelegator reader)
bool IsStartObject(XmlDictionaryReader reader)
void WriteEndObjectHandleExceptions(XmlWriterDelegator writer)
bool IsRootXmlAny(XmlDictionaryString rootName, DataContract contract)
static string GetTypeInfoError(string errorMessage, Type type, Exception innerException)
virtual void InternalWriteStartObject(XmlWriterDelegator writer, object graph)
static void WriteNull(XmlWriterDelegator writer)
static bool IsContractDeclared(DataContract contract, DataContract declaredContract)
static string TryAddLineInfo(XmlReaderDelegator reader, string errorMessage)
void WriteObjectContent(XmlDictionaryWriter writer, object? graph)
virtual ? object ReadObject(XmlReader reader, bool verifyObjectName)
static SerializationException CreateSerializationException(string errorMessage)
virtual void WriteObject(XmlWriter writer, object? graph)
virtual void InternalWriteObjectContent(XmlWriterDelegator writer, object graph)
void WriteObjectHandleExceptions(XmlWriterDelegator writer, object graph)
static SerializationException CreateSerializationException(string errorMessage, Exception innerException)
virtual ? object ReadObject(XmlDictionaryReader reader)
virtual void WriteObjectContent(XmlWriter writer, object? graph)
virtual void InternalWriteObject(XmlWriterDelegator writer, object graph)
void WriteRootElement(XmlWriterDelegator writer, DataContract contract, XmlDictionaryString name, XmlDictionaryString ns, bool needsContractNsAtRoot)
object ReadObjectHandleExceptions(XmlReaderDelegator reader, bool verifyObjectName, DataContractResolver dataContractResolver)
static void CheckNull(object obj, string name)
object ReadObjectHandleExceptions(XmlReaderDelegator reader, bool verifyObjectName)
object? ReadObject(XmlDictionaryReader reader, bool verifyObjectName)
void WriteStartObjectHandleExceptions(XmlWriterDelegator writer, object graph)
virtual void WriteStartObject(XmlWriter writer, object? graph)
void WriteObjectHandleExceptions(XmlWriterDelegator writer, object graph, DataContractResolver dataContractResolver)
virtual void WriteObject(XmlDictionaryWriter writer, object? graph)
void WriteObjectContentHandleExceptions(XmlWriterDelegator writer, object graph)
virtual ? Dictionary< XmlQualifiedName, DataContract > KnownDataContracts
void WriteEndObject(XmlDictionaryWriter writer)
bool IsRootElement(XmlReaderDelegator reader, DataContract contract, XmlDictionaryString name, XmlDictionaryString ns)
virtual void WriteObject(Stream stream, object? graph)
static string ErrorIsStartObject
Definition SR.cs:92
static string ErrorDeserializing
Definition SR.cs:88
static string XmlWriterMustBeInElement
Definition SR.cs:318
static string EncounteredWithNameNamespace
Definition SR.cs:84
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string ErrorWriteStartObject
Definition SR.cs:100
static string ErrorInLine
Definition SR.cs:90
static string ErrorSerializing
Definition SR.cs:94
static string ErrorWriteEndObject
Definition SR.cs:98
static string ErrorTypeInfo
Definition SR.cs:96
Definition SR.cs:7
static Encoding UTF8
Definition Encoding.cs:526
static XmlDictionaryReader CreateTextReader(byte[] buffer, XmlDictionaryReaderQuotas quotas)
static XmlDictionaryReader CreateDictionaryReader(XmlReader reader)
static XmlDictionaryString Empty
static string GetString(XmlDictionaryString s)
static XmlDictionaryWriter CreateDictionaryWriter(XmlWriter writer)
static XmlDictionaryWriter CreateTextWriter(Stream stream)