Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TryConvertJsonElement< TypeToConvert >()

bool System.Text.Json.Nodes.JsonValue< TValue >.TryConvertJsonElement< TypeToConvert > ( [NotNullWhen(true)] out TypeToConvert result)
inlinepackageinherited

Definition at line 502 of file JsonValue.cs.

503 {
505 switch (jsonElement.ValueKind)
506 {
507 case JsonValueKind.Number:
508 if (typeof(TypeToConvert) == typeof(int) || typeof(TypeToConvert) == typeof(int?))
509 {
510 int value;
511 bool result2 = jsonElement.TryGetInt32(out value);
512 result = (TypeToConvert)(object)value;
513 return result2;
514 }
515 if (typeof(TypeToConvert) == typeof(long) || typeof(TypeToConvert) == typeof(long?))
516 {
517 long value2;
518 bool result2 = jsonElement.TryGetInt64(out value2);
519 result = (TypeToConvert)(object)value2;
520 return result2;
521 }
522 if (typeof(TypeToConvert) == typeof(double) || typeof(TypeToConvert) == typeof(double?))
523 {
524 double value3;
525 bool result2 = jsonElement.TryGetDouble(out value3);
526 result = (TypeToConvert)(object)value3;
527 return result2;
528 }
529 if (typeof(TypeToConvert) == typeof(short) || typeof(TypeToConvert) == typeof(short?))
530 {
531 short value4;
532 bool result2 = jsonElement.TryGetInt16(out value4);
533 result = (TypeToConvert)(object)value4;
534 return result2;
535 }
536 if (typeof(TypeToConvert) == typeof(decimal) || typeof(TypeToConvert) == typeof(decimal?))
537 {
538 decimal value5;
539 bool result2 = jsonElement.TryGetDecimal(out value5);
540 result = (TypeToConvert)(object)value5;
541 return result2;
542 }
543 if (typeof(TypeToConvert) == typeof(byte) || typeof(TypeToConvert) == typeof(byte?))
544 {
545 byte value6;
546 bool result2 = jsonElement.TryGetByte(out value6);
547 result = (TypeToConvert)(object)value6;
548 return result2;
549 }
550 if (typeof(TypeToConvert) == typeof(float) || typeof(TypeToConvert) == typeof(float?))
551 {
552 float value7;
553 bool result2 = jsonElement.TryGetSingle(out value7);
554 result = (TypeToConvert)(object)value7;
555 return result2;
556 }
557 if (typeof(TypeToConvert) == typeof(uint) || typeof(TypeToConvert) == typeof(uint?))
558 {
559 uint value8;
560 bool result2 = jsonElement.TryGetUInt32(out value8);
561 result = (TypeToConvert)(object)value8;
562 return result2;
563 }
564 if (typeof(TypeToConvert) == typeof(ushort) || typeof(TypeToConvert) == typeof(ushort?))
565 {
566 ushort value9;
567 bool result2 = jsonElement.TryGetUInt16(out value9);
568 result = (TypeToConvert)(object)value9;
569 return result2;
570 }
571 if (typeof(TypeToConvert) == typeof(ulong) || typeof(TypeToConvert) == typeof(ulong?))
572 {
573 ulong value10;
574 bool result2 = jsonElement.TryGetUInt64(out value10);
575 result = (TypeToConvert)(object)value10;
576 return result2;
577 }
578 if (typeof(TypeToConvert) == typeof(sbyte) || typeof(TypeToConvert) == typeof(sbyte?))
579 {
580 sbyte value11;
581 bool result2 = jsonElement.TryGetSByte(out value11);
582 result = (TypeToConvert)(object)value11;
583 return result2;
584 }
585 break;
586 case JsonValueKind.String:
587 if (typeof(TypeToConvert) == typeof(string))
588 {
589 string @string = jsonElement.GetString();
590 result = (TypeToConvert)(object)@string;
591 return true;
592 }
593 if (typeof(TypeToConvert) == typeof(DateTime) || typeof(TypeToConvert) == typeof(DateTime?))
594 {
596 bool result2 = jsonElement.TryGetDateTime(out value12);
597 result = (TypeToConvert)(object)value12;
598 return result2;
599 }
600 if (typeof(TypeToConvert) == typeof(DateTimeOffset) || typeof(TypeToConvert) == typeof(DateTimeOffset?))
601 {
603 bool result2 = jsonElement.TryGetDateTimeOffset(out value13);
604 result = (TypeToConvert)(object)value13;
605 return result2;
606 }
607 if (typeof(TypeToConvert) == typeof(Guid) || typeof(TypeToConvert) == typeof(Guid?))
608 {
610 bool result2 = jsonElement.TryGetGuid(out value14);
611 result = (TypeToConvert)(object)value14;
612 return result2;
613 }
614 if (typeof(TypeToConvert) == typeof(char) || typeof(TypeToConvert) == typeof(char?))
615 {
616 string string2 = jsonElement.GetString();
617 if (string2.Length == 1)
618 {
619 result = (TypeToConvert)(object)string2[0];
620 return true;
621 }
622 }
623 break;
624 case JsonValueKind.True:
625 case JsonValueKind.False:
626 if (typeof(TypeToConvert) == typeof(bool) || typeof(TypeToConvert) == typeof(bool?))
627 {
628 result = (TypeToConvert)(object)jsonElement.GetBoolean();
629 return true;
630 }
631 break;
632 }
633 result = default(TypeToConvert);
634 return false;
635 }

References System.Text.Json.Nodes.JsonValue< TValue >._value, System.Text.Json.Dictionary, and System.value.