Exemplo n.º 1
0
        public static T?DeserializeStatic(ref JsonReader reader, JsonSerializerOptions options)
        {
            if (reader.ReadIsNull())
            {
                return(null);
            }

            var answer = options.DeserializeWithVerify <T>(ref reader);

            return(answer);
        }
Exemplo n.º 2
0
        public object DeserializeTypeless(ref JsonReader reader, JsonSerializerOptions options)
#endif
        {
            if (reader.ReadIsNull())
            {
                return(null);
            }

            var answer = options.DeserializeWithVerify <T>(ref reader);

            return(answer);
        }
Exemplo n.º 3
0
        public static KeyValuePair <TKey, TValue> DeserializeStatic(ref JsonReader reader, JsonSerializerOptions options)
        {
            if (reader.ReadIsNull())
            {
                throw new JsonParsingException("KeyValuePair`2 cannot be null.");
            }

            reader.ReadIsBeginObjectWithVerify();
            var span = reader.ReadPropertyNameSegmentRaw();

            var key   = default(TKey);
            var value = default(TValue);

            switch (span.Length)
            {
            case 3:
                if (span[0] != 'K' || span[1] != 'e' || span[2] != 'y')
                {
                    goto ERROR;
                }

                key = options.DeserializeWithVerify <TKey>(ref reader);
                break;

            case 5:
                if (span[0] != 'V' || span[1] != 'a' || span[2] != 'l' || span[3] != 'u' || span[4] != 'e')
                {
                    goto ERROR;
                }

                value = options.DeserializeWithVerify <TValue>(ref reader);
                break;

            default:
                goto ERROR;
            }

            reader.ReadIsValueSeparatorWithVerify();
            span = reader.ReadPropertyNameSegmentRaw();

            switch (span.Length)
            {
            case 3:
                if (span[0] != 'K' || span[1] != 'e' || span[2] != 'y')
                {
                    goto ERROR;
                }

                key = options.DeserializeWithVerify <TKey>(ref reader);
                break;

            case 5:
                if (span[0] != 'V' || span[1] != 'a' || span[2] != 'l' || span[3] != 'u' || span[4] != 'e')
                {
                    goto ERROR;
                }

                value = options.DeserializeWithVerify <TValue>(ref reader);
                break;

            default:
                goto ERROR;
            }

            reader.ReadIsEndObjectWithVerify();

#if CSHARP_8_OR_NEWER
            return(new KeyValuePair <TKey, TValue>(key !, value !));
#else
            return(new KeyValuePair <TKey, TValue>(key, value));
#endif
ERROR:
            throw new JsonParsingException("Invalid Property Name.");
        }
Exemplo n.º 4
0
        public static ValueTask <T> DeserializeStatic(ref JsonReader reader, JsonSerializerOptions options)
        {
            var answer = options.DeserializeWithVerify <T>(ref reader);

            return(new ValueTask <T>(answer));
        }