Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
IDictionaryConverter.cs
Go to the documentation of this file.
4
6
7internal sealed class IDictionaryConverter<TDictionary> : JsonDictionaryConverter<TDictionary, string, object> where TDictionary : IDictionary
8{
9 internal override Type RuntimeType
10 {
11 get
12 {
13 if (TypeToConvert.IsAbstract || TypeToConvert.IsInterface)
14 {
16 }
17 return TypeToConvert;
18 }
19 }
20
21 protected override void Add(string key, in object value, JsonSerializerOptions options, ref ReadStack state)
22 {
23 TDictionary val = (TDictionary)state.Current.ReturnValue;
24 val[key] = value;
25 if (base.IsValueType)
26 {
28 }
29 }
30
31 protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state)
32 {
33 JsonTypeInfo jsonTypeInfo = state.Current.JsonTypeInfo;
34 if (TypeToConvert.IsInterface || TypeToConvert.IsAbstract)
35 {
36 if (!TypeToConvert.IsAssignableFrom(RuntimeType))
37 {
39 }
41 return;
42 }
43 if (jsonTypeInfo.CreateObject == null)
44 {
46 }
47 TDictionary val = (TDictionary)jsonTypeInfo.CreateObject();
48 if (val.IsReadOnly)
49 {
51 }
53 }
54
56 {
58 if (state.Current.CollectionEnumerator == null)
59 {
61 if (!dictionaryEnumerator.MoveNext())
62 {
63 return true;
64 }
65 }
66 else
67 {
68 dictionaryEnumerator = (IDictionaryEnumerator)state.Current.CollectionEnumerator;
69 }
70 JsonTypeInfo jsonTypeInfo = state.Current.JsonTypeInfo;
71 if (_valueConverter == null)
72 {
74 }
75 do
76 {
77 if (ShouldFlush(writer, ref state))
78 {
80 return false;
81 }
82 if ((int)state.Current.PropertyState < 2)
83 {
85 object key = dictionaryEnumerator.Key;
86 if (key is string value2)
87 {
88 if (_keyConverter == null)
89 {
91 }
92 _keyConverter.WriteAsPropertyNameCore(writer, value2, options, state.Current.IsWritingExtensionDataProperty);
93 }
94 else
95 {
96 _valueConverter.WriteAsPropertyNameCore(writer, key, options, state.Current.IsWritingExtensionDataProperty);
97 }
98 }
99 object value3 = dictionaryEnumerator.Value;
101 {
103 return false;
104 }
105 state.Current.EndDictionaryElement();
106 }
107 while (dictionaryEnumerator.MoveNext());
108 return true;
109 }
110}
bool ICollection< KeyValuePair< TKey, TValue > >. IsReadOnly
override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state)
override void Add(string key, in object value, JsonSerializerOptions options, ref ReadStack state)
override bool OnWriteResume(Utf8JsonWriter writer, TDictionary value, JsonSerializerOptions options, ref WriteStack state)
bool TryWrite(Utf8JsonWriter writer, in T value, JsonSerializerOptions options, ref WriteStack state)
virtual void WriteAsPropertyNameCore(Utf8JsonWriter writer, T value, JsonSerializerOptions options, bool isWritingExtensionDataProperty)
static void ThrowNotSupportedException_CannotPopulateCollection(Type type, ref Utf8JsonReader reader, ref ReadStack state)
static void ThrowNotSupportedException_DeserializeNoConstructor(Type type, ref Utf8JsonReader reader, ref ReadStack state)