Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DictionaryOfTKeyTValueConverter.cs
Go to the documentation of this file.
3
5
6internal sealed class DictionaryOfTKeyTValueConverter<TCollection, TKey, TValue> : DictionaryDefaultConverter<TCollection, TKey, TValue> where TCollection : Dictionary<TKey, TValue>
7{
8 protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state)
9 {
10 ((TCollection)state.Current.ReturnValue)[key] = value;
11 }
12
13 protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state)
14 {
15 if (state.Current.JsonTypeInfo.CreateObject == null)
16 {
18 }
19 state.Current.ReturnValue = state.Current.JsonTypeInfo.CreateObject();
20 }
21
23 {
25 if (state.Current.CollectionEnumerator == null)
26 {
28 if (!enumerator.MoveNext())
29 {
30 enumerator.Dispose();
31 return true;
32 }
33 }
34 else
35 {
36 enumerator = (Dictionary<TKey, TValue>.Enumerator)(object)state.Current.CollectionEnumerator;
37 }
38 JsonTypeInfo jsonTypeInfo = state.Current.JsonTypeInfo;
39 if (_keyConverter == null)
40 {
41 _keyConverter = JsonDictionaryConverter<TCollection, TKey, TValue>.GetConverter<TKey>(jsonTypeInfo.KeyTypeInfo);
42 }
43 if (_valueConverter == null)
44 {
45 _valueConverter = JsonDictionaryConverter<TCollection, TKey, TValue>.GetConverter<TValue>(jsonTypeInfo.ElementTypeInfo);
46 }
47 if (!state.SupportContinuation && _valueConverter.CanUseDirectReadOrWrite && !state.Current.NumberHandling.HasValue)
48 {
49 do
50 {
51 TKey key = enumerator.Current.Key;
52 _keyConverter.WriteAsPropertyNameCore(writer, key, options, state.Current.IsWritingExtensionDataProperty);
53 _valueConverter.Write(writer, enumerator.Current.Value, options);
54 }
55 while (enumerator.MoveNext());
56 }
57 else
58 {
59 do
60 {
61 if (ShouldFlush(writer, ref state))
62 {
64 return false;
65 }
66 if ((int)state.Current.PropertyState < 2)
67 {
69 TKey key2 = enumerator.Current.Key;
70 _keyConverter.WriteAsPropertyNameCore(writer, key2, options, state.Current.IsWritingExtensionDataProperty);
71 }
72 TValue value2 = enumerator.Current.Value;
73 if (!_valueConverter.TryWrite(writer, in value2, options, ref state))
74 {
76 return false;
77 }
78 state.Current.EndDictionaryElement();
79 }
80 while (enumerator.MoveNext());
81 }
82 enumerator.Dispose();
83 return true;
84 }
85}
override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state)
override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state)
override bool OnWriteResume(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, ref WriteStack state)
static void ThrowNotSupportedException_SerializationNotSupported(Type propertyType)