Пример #1
0
        public object Read(Type expectedType, bool typeIsHint)
        {
            this.depth++;
            if (object.Equals(expectedType, typeof(object)))
            {
                expectedType = null;
            }
            JsonToken jsonToken = this.Tokenize();

            if (!object.Equals(expectedType, null) && !expectedType.IsPrimitive)
            {
                JsonConverter converter = this.Settings.GetConverter(expectedType);
                if (converter != null)
                {
                    if (this.depth <= 0)
                    {
                        if (!converter.convertAtDepthZero)
                        {
                            goto IL_D3;
                        }
                    }
                    try
                    {
                        object obj = this.Read(typeof(Dictionary <string, object>), false);
                        Dictionary <string, object> dictionary = obj as Dictionary <string, object>;
                        if (dictionary == null)
                        {
                            return(null);
                        }
                        object result = converter.Read(this, expectedType, dictionary);
                        this.depth--;
                        return(result);
                    }
                    catch (JsonTypeCoercionException ex)
                    {
                    }
                    this.depth--;
                    return(null);
                }
IL_D3:
                if (typeof(IJsonSerializable).IsAssignableFrom(expectedType))
                {
                    IJsonSerializable jsonSerializable = this.Settings.Coercion.InstantiateObject(expectedType) as IJsonSerializable;
                    jsonSerializable.ReadJson(this);
                    this.depth--;
                    return(jsonSerializable);
                }
            }
            switch (jsonToken)
            {
            case JsonToken.Undefined:
                this.index += JsonReader.LiteralUndefined.Length;
                this.depth--;
                return(null);

            case JsonToken.Null:
                this.index += JsonReader.LiteralNull.Length;
                this.depth--;
                return(null);

            case JsonToken.False:
                this.index += JsonReader.LiteralFalse.Length;
                this.depth--;
                return(false);

            case JsonToken.True:
                this.index += JsonReader.LiteralTrue.Length;
                this.depth--;
                return(true);

            case JsonToken.NaN:
                this.index += JsonReader.LiteralNotANumber.Length;
                this.depth--;
                return(double.NaN);

            case JsonToken.PositiveInfinity:
                this.index += JsonReader.LiteralPositiveInfinity.Length;
                this.depth--;
                return(double.PositiveInfinity);

            case JsonToken.NegativeInfinity:
                this.index += JsonReader.LiteralNegativeInfinity.Length;
                this.depth--;
                return(double.NegativeInfinity);

            case JsonToken.Number:
            {
                object result2 = this.ReadNumber((!typeIsHint) ? expectedType : null);
                this.depth--;
                return(result2);
            }

            case JsonToken.String:
            {
                object result2 = this.ReadString((!typeIsHint) ? expectedType : null);
                this.depth--;
                return(result2);
            }

            case JsonToken.ArrayStart:
            {
                object result2 = this.ReadArray((!typeIsHint) ? expectedType : null);
                this.depth--;
                return(result2);
            }

            case JsonToken.ObjectStart:
            {
                object result2 = this.ReadObject((!typeIsHint) ? expectedType : null);
                this.depth--;
                return(result2);
            }
            }
            this.depth--;
            return(null);
        }