Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ReflectionWriteValue()

void System.Runtime.Serialization.ReflectionClassWriter.ReflectionWriteValue ( XmlWriterDelegator xmlWriter,
XmlObjectSerializerWriteContext context,
Type type,
object value,
bool writeXsiType,
PrimitiveDataContract primitiveContractForParamType )
inlineinherited

Definition at line 31 of file ReflectionClassWriter.cs.

32 {
33 Type type2 = type;
34 object obj = value;
35 bool flag = type2.IsGenericType && type2.GetGenericTypeDefinition() == Globals.TypeOfNullable;
36 if (type2.IsValueType && !flag)
37 {
39 {
40 primitiveContractForParamType.WriteXmlValue(xmlWriter, obj, context);
41 }
42 else
43 {
44 ReflectionInternalSerialize(xmlWriter, context, obj, obj.GetType().TypeHandle.Equals(type2.TypeHandle), writeXsiType, type2);
45 }
46 return;
47 }
48 if (flag)
49 {
50 if (obj == null)
51 {
52 type2 = Nullable.GetUnderlyingType(type2);
53 }
54 else
55 {
56 MethodInfo method = type2.GetMethod("get_Value", Type.EmptyTypes);
57 obj = method.Invoke(obj, Array.Empty<object>());
58 type2 = obj.GetType();
59 }
60 }
61 if (obj == null)
62 {
63 context.WriteNull(xmlWriter, type2, DataContract.IsTypeSerializable(type2));
64 return;
65 }
66 PrimitiveDataContract primitiveDataContract = (flag ? PrimitiveDataContract.GetPrimitiveDataContract(type2) : primitiveContractForParamType);
67 if (primitiveDataContract != null && primitiveDataContract.UnderlyingType != Globals.TypeOfObject && !writeXsiType)
68 {
69 primitiveDataContract.WriteXmlValue(xmlWriter, obj, context);
70 }
71 else if (obj == null && (type2 == Globals.TypeOfObject || (flag && type2.IsValueType)))
72 {
73 context.WriteNull(xmlWriter, type2, DataContract.IsTypeSerializable(type2));
74 }
75 else
76 {
77 ReflectionInternalSerialize(xmlWriter, context, obj, obj.GetType().TypeHandle.Equals(type2.TypeHandle), writeXsiType, type2, flag);
78 }
79 }
object? Invoke(object? obj, object?[]? parameters)
void ReflectionInternalSerialize(XmlWriterDelegator xmlWriter, XmlObjectSerializerWriteContext context, object obj, bool isDeclaredType, bool writeXsiType, Type memberType, bool isNullableOfT=false)

References System.Runtime.Serialization.Dictionary, System.Type.EmptyTypes, System.Type.GetGenericTypeDefinition(), System.Runtime.Serialization.PrimitiveDataContract.GetPrimitiveDataContract(), System.Nullable< T >.GetUnderlyingType(), System.Reflection.MethodBase.Invoke(), System.Runtime.Serialization.DataContract.IsTypeSerializable(), System.obj, System.Runtime.Serialization.ReflectionClassWriter.ReflectionInternalSerialize(), System.type, System.Runtime.Serialization.Globals.TypeOfNullable, System.Runtime.Serialization.Globals.TypeOfObject, System.value, System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteNull(), and System.Runtime.Serialization.PrimitiveDataContract.WriteXmlValue().

Referenced by System.Runtime.Serialization.Json.ReflectionJsonFormatWriter.ReflectionWriteCollection(), and System.Runtime.Serialization.Json.ReflectionJsonClassWriter.ReflectionWriteMembers().