Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ReflectionJsonFormatWriter.cs
Go to the documentation of this file.
3using System.Xml;
4
6
7internal sealed class ReflectionJsonFormatWriter
8{
10
11 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
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.")]
19 {
21 {
22 throw new ArgumentException("xmlWriter");
23 }
25 if (collectionContract.Kind == CollectionKind.Array)
26 {
30 {
34 for (int i = 0; i < array.Length; i++)
35 {
39 }
40 }
41 return;
42 }
43 collectionContract.IncrementCollectionCount(jsonWriterDelegator, obj, context);
44 IEnumerator enumeratorForCollection = collectionContract.GetEnumeratorForCollection(obj);
47 if (flag && useSimpleDictionaryFormat)
48 {
52 while (enumeratorForCollection.MoveNext())
53 {
54 object current = enumeratorForCollection.Current;
55 object key = ((IKeyValue)current).Key;
56 object value = ((IKeyValue)current).Value;
60 }
61 return;
62 }
66 {
67 while (enumeratorForCollection.MoveNext())
68 {
69 object current2 = enumeratorForCollection.Current;
70 context.IncrementItemCount(1);
72 }
73 return;
74 }
75 Type collectionElementType = collectionContract.GetCollectionElementType();
79 if (flag2)
80 {
83 }
84 while (enumeratorForCollection.MoveNext())
85 {
86 object current3 = enumeratorForCollection.Current;
87 context.IncrementItemCount(1);
89 if (flag2)
90 {
91 jsonDataContract.WriteJsonValue(jsonWriterDelegator, current3, context, collectionContract.ItemType.TypeHandle);
92 }
93 else
94 {
96 }
98 }
99 }
100
102 {
103 xmlWriter.WriteAttributeString(null, "type", null, "object");
104 }
105
106 [RequiresUnreferencedCode("Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved.")]
108 {
110 if (primitiveDataContract == null)
111 {
112 return false;
113 }
115 switch (itemType.GetTypeCode())
116 {
117 case TypeCode.Boolean:
119 jsonWriter.WriteJsonBooleanArray((bool[])obj, collectionItemName, itemNamespace);
120 break;
121 case TypeCode.DateTime:
123 jsonWriter.WriteJsonDateTimeArray((DateTime[])obj, collectionItemName, itemNamespace);
124 break;
125 case TypeCode.Decimal:
127 jsonWriter.WriteJsonDecimalArray((decimal[])obj, collectionItemName, itemNamespace);
128 break;
129 case TypeCode.Int32:
131 jsonWriter.WriteJsonInt32Array((int[])obj, collectionItemName, itemNamespace);
132 break;
133 case TypeCode.Int64:
135 jsonWriter.WriteJsonInt64Array((long[])obj, collectionItemName, itemNamespace);
136 break;
137 case TypeCode.Single:
139 jsonWriter.WriteJsonSingleArray((float[])obj, collectionItemName, itemNamespace);
140 break;
141 case TypeCode.Double:
143 jsonWriter.WriteJsonDoubleArray((double[])obj, collectionItemName, itemNamespace);
144 break;
145 default:
146 return false;
147 }
148 return true;
149 }
150
152 {
153 xmlWriter.WriteAttributeString(null, "type", string.Empty, "array");
154 }
155}
static JsonDataContract GetJsonDataContract(DataContract traditionalDataContract)
void ReflectionWriteStartElement(XmlWriterDelegator xmlWriter, XmlDictionaryString name)
bool ReflectionTryWritePrimitiveArray(JsonWriterDelegator jsonWriter, object obj, Type underlyingType, Type itemType, XmlDictionaryString collectionItemName)
void ReflectionWriteClass(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, ClassDataContract classContract, XmlDictionaryString[] memberNames)
void ReflectionWriteCollection(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, CollectionDataContract collectionContract)
static PrimitiveDataContract GetPrimitiveDataContract(Type type)
void ReflectionWriteValue(XmlWriterDelegator xmlWriter, XmlObjectSerializerWriteContext context, Type type, object value, bool writeXsiType, PrimitiveDataContract primitiveContractForParamType)
void ReflectionWriteClass(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract classContract, XmlDictionaryString[] memberNames)
virtual Type[] GetGenericArguments()
Definition Type.cs:500
TypeCode
Definition TypeCode.cs:4