Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
JsonNode.cs
Go to the documentation of this file.
2using System.IO;
4
6
7public abstract class JsonNode
8{
10
12
14 {
15 get
16 {
17 if (!_options.HasValue && Parent != null)
18 {
20 }
21 return _options;
22 }
23 }
24
26 {
27 get
28 {
29 return _parent;
30 }
31 internal set
32 {
33 _parent = value;
34 }
35 }
36
38 {
39 get
40 {
41 JsonNode parent = Parent;
42 if (parent == null)
43 {
44 return this;
45 }
46 while (parent.Parent != null)
47 {
48 parent = parent.Parent;
49 }
50 return parent;
51 }
52 }
53
54 public JsonNode? this[int index]
55 {
56 get
57 {
58 return AsArray().GetItem(index);
59 }
60 set
61 {
63 }
64 }
65
66 public JsonNode? this[string propertyName]
67 {
68 get
69 {
71 }
72 set
73 {
75 }
76 }
77
79 {
81 }
82
84 {
85 if (this is JsonArray result)
86 {
87 return result;
88 }
90 }
91
93 {
94 if (this is JsonObject result)
95 {
96 return result;
97 }
99 }
100
102 {
103 if (this is JsonValue result)
104 {
105 return result;
106 }
108 }
109
110 public string GetPath()
111 {
112 if (Parent == null)
113 {
114 return "$";
115 }
117 GetPath(list, null);
119 for (int num = list.Count - 1; num >= 0; num--)
120 {
121 stringBuilder.Append(list[num]);
122 }
123 return stringBuilder.ToString();
124 }
125
126 internal abstract void GetPath(List<string> path, JsonNode child);
127
128 public virtual T GetValue<T>()
129 {
131 }
132
133 internal void AssignParent(JsonNode parent)
134 {
135 if (Parent != null)
136 {
138 }
139 for (JsonNode jsonNode = parent; jsonNode != null; jsonNode = jsonNode.Parent)
140 {
141 if (jsonNode == this)
142 {
144 }
145 }
146 Parent = parent;
147 }
148
149 public static implicit operator JsonNode(bool value)
150 {
151 return JsonValue.Create(value);
152 }
153
154 public static implicit operator JsonNode?(bool? value)
155 {
156 return JsonValue.Create(value);
157 }
158
159 public static implicit operator JsonNode(byte value)
160 {
161 return JsonValue.Create(value);
162 }
163
164 public static implicit operator JsonNode?(byte? value)
165 {
166 return JsonValue.Create(value);
167 }
168
169 public static implicit operator JsonNode(char value)
170 {
171 return JsonValue.Create(value);
172 }
173
174 public static implicit operator JsonNode?(char? value)
175 {
176 return JsonValue.Create(value);
177 }
178
179 public static implicit operator JsonNode(DateTime value)
180 {
181 return JsonValue.Create(value);
182 }
183
184 public static implicit operator JsonNode?(DateTime? value)
185 {
186 return JsonValue.Create(value);
187 }
188
189 public static implicit operator JsonNode(DateTimeOffset value)
190 {
191 return JsonValue.Create(value);
192 }
193
194 public static implicit operator JsonNode?(DateTimeOffset? value)
195 {
196 return JsonValue.Create(value);
197 }
198
199 public static implicit operator JsonNode(decimal value)
200 {
201 return JsonValue.Create(value);
202 }
203
204 public static implicit operator JsonNode?(decimal? value)
205 {
206 return JsonValue.Create(value);
207 }
208
209 public static implicit operator JsonNode(double value)
210 {
211 return JsonValue.Create(value);
212 }
213
214 public static implicit operator JsonNode?(double? value)
215 {
216 return JsonValue.Create(value);
217 }
218
219 public static implicit operator JsonNode(Guid value)
220 {
221 return JsonValue.Create(value);
222 }
223
224 public static implicit operator JsonNode?(Guid? value)
225 {
226 return JsonValue.Create(value);
227 }
228
229 public static implicit operator JsonNode(short value)
230 {
231 return JsonValue.Create(value);
232 }
233
234 public static implicit operator JsonNode?(short? value)
235 {
236 return JsonValue.Create(value);
237 }
238
239 public static implicit operator JsonNode(int value)
240 {
241 return JsonValue.Create(value);
242 }
243
244 public static implicit operator JsonNode?(int? value)
245 {
246 return JsonValue.Create(value);
247 }
248
249 public static implicit operator JsonNode(long value)
250 {
251 return JsonValue.Create(value);
252 }
253
254 public static implicit operator JsonNode?(long? value)
255 {
256 return JsonValue.Create(value);
257 }
258
259 [CLSCompliant(false)]
260 public static implicit operator JsonNode(sbyte value)
261 {
262 return JsonValue.Create(value);
263 }
264
265 [CLSCompliant(false)]
266 public static implicit operator JsonNode?(sbyte? value)
267 {
268 return JsonValue.Create(value);
269 }
270
271 public static implicit operator JsonNode(float value)
272 {
273 return JsonValue.Create(value);
274 }
275
276 public static implicit operator JsonNode?(float? value)
277 {
278 return JsonValue.Create(value);
279 }
280
281 public static implicit operator JsonNode?(string? value)
282 {
283 return JsonValue.Create(value);
284 }
285
286 [CLSCompliant(false)]
287 public static implicit operator JsonNode(ushort value)
288 {
289 return JsonValue.Create(value);
290 }
291
292 [CLSCompliant(false)]
293 public static implicit operator JsonNode?(ushort? value)
294 {
295 return JsonValue.Create(value);
296 }
297
298 [CLSCompliant(false)]
299 public static implicit operator JsonNode(uint value)
300 {
301 return JsonValue.Create(value);
302 }
303
304 [CLSCompliant(false)]
305 public static implicit operator JsonNode?(uint? value)
306 {
307 return JsonValue.Create(value);
308 }
309
310 [CLSCompliant(false)]
311 public static implicit operator JsonNode(ulong value)
312 {
313 return JsonValue.Create(value);
314 }
315
316 [CLSCompliant(false)]
317 public static implicit operator JsonNode?(ulong? value)
318 {
319 return JsonValue.Create(value);
320 }
321
322 public static explicit operator bool(JsonNode value)
323 {
324 return value.GetValue<bool>();
325 }
326
327 public static explicit operator bool?(JsonNode? value)
328 {
329 return value?.GetValue<bool>();
330 }
331
332 public static explicit operator byte(JsonNode value)
333 {
334 return value.GetValue<byte>();
335 }
336
337 public static explicit operator byte?(JsonNode? value)
338 {
339 return value?.GetValue<byte>();
340 }
341
342 public static explicit operator char(JsonNode value)
343 {
344 return value.GetValue<char>();
345 }
346
347 public static explicit operator char?(JsonNode? value)
348 {
349 return value?.GetValue<char>();
350 }
351
352 public static explicit operator DateTime(JsonNode value)
353 {
354 return value.GetValue<DateTime>();
355 }
356
357 public static explicit operator DateTime?(JsonNode? value)
358 {
359 return value?.GetValue<DateTime>();
360 }
361
362 public static explicit operator DateTimeOffset(JsonNode value)
363 {
364 return value.GetValue<DateTimeOffset>();
365 }
366
367 public static explicit operator DateTimeOffset?(JsonNode? value)
368 {
369 return value?.GetValue<DateTimeOffset>();
370 }
371
372 public static explicit operator decimal(JsonNode value)
373 {
374 return value.GetValue<decimal>();
375 }
376
377 public static explicit operator decimal?(JsonNode? value)
378 {
379 return value?.GetValue<decimal>();
380 }
381
382 public static explicit operator double(JsonNode value)
383 {
384 return value.GetValue<double>();
385 }
386
387 public static explicit operator double?(JsonNode? value)
388 {
389 return value?.GetValue<double>();
390 }
391
392 public static explicit operator Guid(JsonNode value)
393 {
394 return value.GetValue<Guid>();
395 }
396
397 public static explicit operator Guid?(JsonNode? value)
398 {
399 return value?.GetValue<Guid>();
400 }
401
402 public static explicit operator short(JsonNode value)
403 {
404 return value.GetValue<short>();
405 }
406
407 public static explicit operator short?(JsonNode? value)
408 {
409 return value?.GetValue<short>();
410 }
411
412 public static explicit operator int(JsonNode value)
413 {
414 return value.GetValue<int>();
415 }
416
417 public static explicit operator int?(JsonNode? value)
418 {
419 return value?.GetValue<int>();
420 }
421
422 public static explicit operator long(JsonNode value)
423 {
424 return value.GetValue<long>();
425 }
426
427 public static explicit operator long?(JsonNode? value)
428 {
429 return value?.GetValue<long>();
430 }
431
432 [CLSCompliant(false)]
433 public static explicit operator sbyte(JsonNode value)
434 {
435 return value.GetValue<sbyte>();
436 }
437
438 [CLSCompliant(false)]
439 public static explicit operator sbyte?(JsonNode? value)
440 {
441 return value?.GetValue<sbyte>();
442 }
443
444 public static explicit operator float(JsonNode value)
445 {
446 return value.GetValue<float>();
447 }
448
449 public static explicit operator float?(JsonNode? value)
450 {
451 return value?.GetValue<float>();
452 }
453
454 public static explicit operator string?(JsonNode? value)
455 {
456 return value?.GetValue<string>();
457 }
458
459 [CLSCompliant(false)]
460 public static explicit operator ushort(JsonNode value)
461 {
462 return value.GetValue<ushort>();
463 }
464
465 [CLSCompliant(false)]
466 public static explicit operator ushort?(JsonNode? value)
467 {
468 return value?.GetValue<ushort>();
469 }
470
471 [CLSCompliant(false)]
472 public static explicit operator uint(JsonNode value)
473 {
474 return value.GetValue<uint>();
475 }
476
477 [CLSCompliant(false)]
478 public static explicit operator uint?(JsonNode? value)
479 {
480 return value?.GetValue<uint>();
481 }
482
483 [CLSCompliant(false)]
484 public static explicit operator ulong(JsonNode value)
485 {
486 return value.GetValue<ulong>();
487 }
488
489 [CLSCompliant(false)]
490 public static explicit operator ulong?(JsonNode? value)
491 {
492 return value?.GetValue<ulong>();
493 }
494
496 {
497 JsonElement element = JsonElement.ParseValue(ref reader);
498 return JsonNodeConverter.Create(element, nodeOptions);
499 }
500
502 {
503 if (json == null)
504 {
505 throw new ArgumentNullException("json");
506 }
508 return JsonNodeConverter.Create(element, nodeOptions);
509 }
510
516
518 {
519 if (utf8Json == null)
520 {
521 throw new ArgumentNullException("utf8Json");
522 }
524 return JsonNodeConverter.Create(element, nodeOptions);
525 }
526
528 {
530 using (Utf8JsonWriter writer = new Utf8JsonWriter(pooledByteBufferWriter, options?.GetWriterOptions() ?? default(JsonWriterOptions)))
531 {
533 }
534 return JsonHelpers.Utf8GetString(pooledByteBufferWriter.WrittenMemory.ToArray());
535 }
536
537 public override string ToString()
538 {
539 if (this is JsonValue)
540 {
542 {
543 return jsonValue.Value;
544 }
545 if (this is JsonValue<JsonElement> { Value: { ValueKind: JsonValueKind.String }, Value: var value2 })
546 {
547 return value2.GetString();
548 }
549 }
552 {
553 Indented = true
554 }))
555 {
557 }
558 return JsonHelpers.Utf8GetString(pooledByteBufferWriter.WrittenMemory.ToArray());
559 }
560
562}
static string NodeWrongType
Definition SR.cs:300
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7
static string Utf8GetString(ReadOnlySpan< byte > bytes)
void SetItem(int index, JsonNode value)
Definition JsonArray.cs:155
JsonNode GetItem(int index)
Definition JsonArray.cs:150
void AssignParent(JsonNode parent)
Definition JsonNode.cs:133
string ToJsonString(JsonSerializerOptions? options=null)
Definition JsonNode.cs:527
void WriteTo(Utf8JsonWriter writer, JsonSerializerOptions? options=null)
static ? JsonNode Parse(ref Utf8JsonReader reader, JsonNodeOptions? nodeOptions=null)
Definition JsonNode.cs:495
JsonNodeOptions? _options
Definition JsonNode.cs:11
static ? JsonNode Parse(ReadOnlySpan< byte > utf8Json, JsonNodeOptions? nodeOptions=null, JsonDocumentOptions documentOptions=default(JsonDocumentOptions))
Definition JsonNode.cs:511
void GetPath(List< string > path, JsonNode child)
JsonNode(JsonNodeOptions? options=null)
Definition JsonNode.cs:78
override string ToString()
Definition JsonNode.cs:537
static ? JsonNode Parse(Stream utf8Json, JsonNodeOptions? nodeOptions=null, JsonDocumentOptions documentOptions=default(JsonDocumentOptions))
Definition JsonNode.cs:517
static ? JsonNode Parse(string json, JsonNodeOptions? nodeOptions=null, JsonDocumentOptions documentOptions=default(JsonDocumentOptions))
Definition JsonNode.cs:501
JsonNode GetItem(string propertyName)
void SetItem(string propertyName, JsonNode value)
static JsonValue Create(bool value, JsonNodeOptions? options=null)
Definition JsonValue.cs:12
static JsonNode Create(JsonElement element, JsonNodeOptions? options)
static void ThrowInvalidOperationException_NodeAlreadyHasParent()
static void ThrowInvalidOperationException_NodeCycleDetected()
static JsonElement ParseValue(ref Utf8JsonReader reader)