Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ObjectWithParameterizedConstructorConverter.cs
Go to the documentation of this file.
6
8
10{
11 internal sealed override bool ConstructorIsParameterized => true;
12
14 {
15 ArgumentState ctorArgumentState = state.Current.CtorArgumentState;
16 object obj;
17 if (state.UseFastPath)
18 {
19 ReadOnlySpan<byte> originalSpan = reader.OriginalSpan;
21 obj = (T)CreateObject(ref state.Current);
23 {
24 jsonOnDeserializing.OnDeserializing();
25 }
26 if (ctorArgumentState.FoundPropertyCount > 0)
27 {
28 (JsonPropertyInfo, JsonReaderState, long, byte[], string)[] foundProperties = ctorArgumentState.FoundProperties;
29 for (int i = 0; i < ctorArgumentState.FoundPropertyCount; i++)
30 {
32 long item2 = foundProperties[i].Item3;
33 byte[] item3 = foundProperties[i].Item4;
34 string item4 = foundProperties[i].Item5;
38 state.Current.NumberHandling = item.NumberHandling;
39 bool flag = item4 != null;
40 if (flag)
41 {
44 }
45 ObjectDefaultConverter<T>.ReadPropertyValue(obj, ref state, ref reader2, item, flag);
46 }
47 (JsonPropertyInfo, JsonReaderState, long, byte[], string)[] foundProperties2 = ctorArgumentState.FoundProperties;
50 }
51 }
52 else
53 {
54 if (state.Current.ObjectState == StackFrameObjectState.None)
55 {
57 BeginRead(ref state, ref reader, options);
58 }
60 {
61 value = default(T);
62 return false;
63 }
64 obj = (T)CreateObject(ref state.Current);
66 {
67 jsonOnDeserializing2.OnDeserializing();
68 }
69 if (ctorArgumentState.FoundPropertyCount > 0)
70 {
71 for (int j = 0; j < ctorArgumentState.FoundPropertyCount; j++)
72 {
73 JsonPropertyInfo item5 = ctorArgumentState.FoundPropertiesAsync[j].Item1;
74 object item6 = ctorArgumentState.FoundPropertiesAsync[j].Item2;
75 string item7 = ctorArgumentState.FoundPropertiesAsync[j].Item3;
76 if (item7 == null)
77 {
78 item5.SetExtensionDictionaryAsObject(obj, item6);
79 continue;
80 }
82 object valueAsObject = item5.GetValueAsObject(obj);
84 {
86 }
87 else
88 {
90 }
91 }
92 (JsonPropertyInfo, object, string)[] foundPropertiesAsync = ctorArgumentState.FoundPropertiesAsync;
95 }
96 }
98 {
99 jsonOnDeserialized.OnDeserialized();
100 }
102 value = (T)obj;
103 if (state.Current.PropertyRefCache != null)
104 {
105 state.Current.JsonTypeInfo.UpdateSortedPropertyCache(ref state.Current);
106 }
107 if (ctorArgumentState.ParameterRefCache != null)
108 {
109 state.Current.JsonTypeInfo.UpdateSortedParameterCache(ref state.Current);
110 }
111 return true;
112 }
113
115
117
118 protected abstract object CreateObject(ref ReadStackFrame frame);
119
120 [MethodImpl(MethodImplOptions.AggressiveInlining)]
122 {
123 BeginRead(ref state, ref reader, options);
124 while (true)
125 {
126 reader.ReadWithVerify();
127 JsonTokenType tokenType = reader.TokenType;
128 if (tokenType == JsonTokenType.EndObject)
129 {
130 break;
131 }
133 {
134 reader.ReadWithVerify();
135 if (!jsonParameterInfo.ShouldDeserialize)
136 {
137 reader.Skip();
138 state.Current.EndConstructorParameter();
139 }
140 else
141 {
143 state.Current.EndConstructorParameter();
144 }
145 continue;
146 }
150 if (jsonPropertyInfo.ShouldDeserialize)
151 {
152 ArgumentState ctorArgumentState = state.Current.CtorArgumentState;
153 if (ctorArgumentState.FoundProperties == null)
154 {
155 ctorArgumentState.FoundProperties = ArrayPool<(JsonPropertyInfo, JsonReaderState, long, byte[], string)>.Shared.Rent(Math.Max(1, state.Current.JsonTypeInfo.PropertyCache.Count));
156 }
157 else if (ctorArgumentState.FoundPropertyCount == ctorArgumentState.FoundProperties.Length)
158 {
159 (JsonPropertyInfo, JsonReaderState, long, byte[], string)[] array = ArrayPool<(JsonPropertyInfo, JsonReaderState, long, byte[], string)>.Shared.Rent(ctorArgumentState.FoundProperties.Length * 2);
160 ctorArgumentState.FoundProperties.CopyTo(array, 0);
161 (JsonPropertyInfo, JsonReaderState, long, byte[], string)[] foundProperties = ctorArgumentState.FoundProperties;
164 }
165 ctorArgumentState.FoundProperties[ctorArgumentState.FoundPropertyCount++] = (jsonPropertyInfo, reader.CurrentState, reader.BytesConsumed, state.Current.JsonPropertyName, state.Current.JsonPropertyNameAsString);
166 }
167 reader.Skip();
168 state.Current.EndProperty();
169 }
170 }
171
173 {
174 while (true)
175 {
176 if (state.Current.PropertyState == StackFramePropertyState.None)
177 {
179 if (!reader.Read())
180 {
181 return false;
182 }
183 }
186 if ((int)state.Current.PropertyState < 2)
187 {
189 JsonTokenType tokenType = reader.TokenType;
190 if (tokenType == JsonTokenType.EndObject)
191 {
192 return true;
193 }
195 {
196 jsonPropertyInfo = null;
197 }
198 else
199 {
203 }
204 }
205 else
206 {
207 jsonParameterInfo = state.Current.CtorArgumentState.JsonParameterInfo;
208 jsonPropertyInfo = state.Current.JsonPropertyInfo;
209 }
210 if (jsonParameterInfo != null)
211 {
213 {
214 return false;
215 }
216 }
218 {
219 break;
220 }
221 }
222 return false;
223 }
224
225 [MethodImpl(MethodImplOptions.AggressiveInlining)]
227 {
228 if ((int)state.Current.PropertyState < 3)
229 {
230 if (!jsonParameterInfo.ShouldDeserialize)
231 {
232 if (!reader.TrySkip())
233 {
234 return false;
235 }
236 state.Current.EndConstructorParameter();
237 return true;
238 }
240 if (!JsonConverter.SingleValueReadWithReadAhead(jsonParameterInfo.ConverterBase.ConverterStrategy, ref reader, ref state))
241 {
242 return false;
243 }
244 }
246 {
247 return false;
248 }
249 state.Current.EndConstructorParameter();
250 return true;
251 }
252
253 [MethodImpl(MethodImplOptions.AggressiveInlining)]
255 {
256 if ((int)state.Current.PropertyState < 3)
257 {
258 if (!jsonPropertyInfo.ShouldDeserialize)
259 {
260 if (!reader.TrySkip())
261 {
262 return false;
263 }
264 state.Current.EndProperty();
265 return true;
266 }
268 {
269 return false;
270 }
271 }
272 object value;
273 if (state.Current.UseExtensionProperty)
274 {
275 if (!jsonPropertyInfo.ReadJsonExtensionDataValue(ref state, ref reader, out value))
276 {
277 return false;
278 }
279 }
280 else if (!jsonPropertyInfo.ReadJsonAsObject(ref state, ref reader, out value))
281 {
282 return false;
283 }
284 ArgumentState ctorArgumentState = state.Current.CtorArgumentState;
285 if (ctorArgumentState.FoundPropertiesAsync == null)
286 {
287 ctorArgumentState.FoundPropertiesAsync = ArrayPool<(JsonPropertyInfo, object, string)>.Shared.Rent(Math.Max(1, state.Current.JsonTypeInfo.PropertyCache.Count));
288 }
289 else if (ctorArgumentState.FoundPropertyCount == ctorArgumentState.FoundPropertiesAsync.Length)
290 {
291 (JsonPropertyInfo, object, string)[] array = ArrayPool<(JsonPropertyInfo, object, string)>.Shared.Rent(ctorArgumentState.FoundPropertiesAsync.Length * 2);
292 ctorArgumentState.FoundPropertiesAsync.CopyTo(array, 0);
293 (JsonPropertyInfo, object, string)[] foundPropertiesAsync = ctorArgumentState.FoundPropertiesAsync;
296 }
297 ctorArgumentState.FoundPropertiesAsync[ctorArgumentState.FoundPropertyCount++] = (jsonPropertyInfo, value, state.Current.JsonPropertyNameAsString);
298 state.Current.EndProperty();
299 return true;
300 }
301
302 [MethodImpl(MethodImplOptions.AggressiveInlining)]
304 {
305 if (reader.TokenType != JsonTokenType.StartObject)
306 {
308 }
309 if (state.Current.JsonTypeInfo.ParameterCount != state.Current.JsonTypeInfo.ParameterCache.Count)
310 {
312 }
315 }
316
317 protected virtual void EndRead(ref ReadStack state)
318 {
319 }
320
331}
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
void Return(T[] array, bool clearArray=false)
T[] Rent(int minimumLength)
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static JsonPropertyInfo LookupProperty(object obj, ReadOnlySpan< byte > unescapedPropertyName, ref ReadStack state, JsonSerializerOptions options, out bool useExtensionProperty, bool createExtensionProperty=true)
static ReadOnlySpan< byte > GetPropertyName(ref ReadStack state, ref Utf8JsonReader reader, JsonSerializerOptions options)
static void CreateDataExtensionProperty(object obj, JsonPropertyInfo jsonPropertyInfo, JsonSerializerOptions options)
static bool ReadAheadPropertyValue(ref ReadStack state, ref Utf8JsonReader reader, JsonPropertyInfo jsonPropertyInfo)
void InitializeConstructorArgumentCaches(ref ReadStack state, JsonSerializerOptions options)
bool HandleConstructorArgumentWithContinuation(ref ReadStack state, ref Utf8JsonReader reader, JsonParameterInfo jsonParameterInfo)
void ReadConstructorArguments(ref ReadStack state, ref Utf8JsonReader reader, JsonSerializerOptions options)
bool ReadAndCacheConstructorArgument(ref ReadStack state, ref Utf8JsonReader reader, JsonParameterInfo jsonParameterInfo)
override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, [MaybeNullWhen(false)] out T value)
bool ReadConstructorArgumentsWithContinuation(ref ReadStack state, ref Utf8JsonReader reader, JsonSerializerOptions options)
bool HandlePropertyWithContinuation(ref ReadStack state, ref Utf8JsonReader reader, JsonPropertyInfo jsonPropertyInfo)
virtual bool TryLookupConstructorParameter(ref ReadStack state, ref Utf8JsonReader reader, JsonSerializerOptions options, out JsonParameterInfo jsonParameterInfo)
void BeginRead(ref ReadStack state, ref Utf8JsonReader reader, JsonSerializerOptions options)
static bool SingleValueReadWithReadAhead(ConverterStrategy converterStrategy, ref Utf8JsonReader reader, ref ReadStack state)
static void ThrowJsonException_DeserializeUnableToConvertValue(Type propertyType)
static void ThrowInvalidOperationException_ConstructorParameterIncompleteBinding(Type parentType)