Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
KeyValuePairConverter.cs
Go to the documentation of this file.
4
6
7internal sealed class KeyValuePairConverter<TKey, TValue> : SmallObjectWithParameterizedConstructorConverter<KeyValuePair<TKey, TValue>, TKey, TValue, object, object>
8{
9 private string _keyName;
10
11 private string _valueName;
12
13 private static readonly ConstructorInfo s_constructorInfo = typeof(KeyValuePair<TKey, TValue>).GetConstructor(new Type[2]
14 {
15 typeof(TKey),
16 typeof(TValue)
17 });
18
20 {
21 JsonNamingPolicy propertyNamingPolicy = options.PropertyNamingPolicy;
22 if (propertyNamingPolicy == null)
23 {
24 _keyName = "Key";
25 _valueName = "Value";
26 }
27 else
28 {
29 _keyName = propertyNamingPolicy.ConvertName("Key");
30 _valueName = propertyNamingPolicy.ConvertName("Value");
31 }
33 }
34
36 {
37 JsonTypeInfo jsonTypeInfo = state.Current.JsonTypeInfo;
38 ArgumentState ctorArgumentState = state.Current.CtorArgumentState;
39 bool propertyNameCaseInsensitive = options.PropertyNameCaseInsensitive;
40 string @string = reader.GetString();
43 {
44 jsonParameterInfo = jsonTypeInfo.ParameterCache[_keyName];
46 }
47 else
48 {
50 {
52 jsonParameterInfo = null;
53 return false;
54 }
57 }
58 ctorArgumentState.ParameterIndex++;
61 return true;
62 }
63
64 protected override void EndRead(ref ReadStack state)
65 {
66 if (state.Current.CtorArgumentState.ParameterIndex != 2)
67 {
69 }
70 }
71
73 {
74 if (!(propertyName == _keyName) && (!caseInsensitiveMatch || !string.Equals(propertyName, _keyName, StringComparison.OrdinalIgnoreCase)))
75 {
76 return propertyName == "Key";
77 }
78 return true;
79 }
80
82 {
83 if (!(propertyName == _valueName) && (!caseInsensitiveMatch || !string.Equals(propertyName, _valueName, StringComparison.OrdinalIgnoreCase)))
84 {
85 return propertyName == "Value";
86 }
87 return true;
88 }
89}
bool FoundValueProperty(string propertyName, bool caseInsensitiveMatch)
bool FoundKeyProperty(string propertyName, bool caseInsensitiveMatch)
override void Initialize(JsonSerializerOptions options, JsonTypeInfo jsonTypeInfo=null)
override bool TryLookupConstructorParameter(ref ReadStack state, ref Utf8JsonReader reader, JsonSerializerOptions options, out JsonParameterInfo jsonParameterInfo)
static void ThrowJsonException(string message=null)