public Double DeserializeFromPropertyName(ref JsonReader reader, IJsonFormatterResolver formatterResolver) { var key = reader.ReadStringSegmentRaw(); int _; return(NumberConverter.ReadDouble(key.Array, key.Offset, out _)); }
public object Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) { var token = reader.GetCurrentJsonToken(); switch (token) { case JsonToken.BeginObject: { var dict = new Dictionary <string, object>(); reader.ReadIsBeginObjectWithVerify(); var count = 0; while (!reader.ReadIsEndObjectWithSkipValueSeparator(ref count)) { var key = reader.ReadPropertyName(); var value = Deserialize(ref reader, formatterResolver); dict.Add(key, value); } return(dict); } case JsonToken.BeginArray: { var list = new List <object>(4); reader.ReadIsBeginArrayWithVerify(); var count = 0; while (!reader.ReadIsEndArrayWithSkipValueSeparator(ref count)) { list.Add(Deserialize(ref reader, formatterResolver)); } return(list); } case JsonToken.Number: var numberSegment = reader.ReadNumberSegment(); // conditional operator here would cast both to double, so don't use. if (numberSegment.IsDouble()) { return(NumberConverter.ReadDouble(numberSegment.Array, numberSegment.Offset, out _)); } // TODO: Check arraysegment to determine if larger than int64? return(NumberConverter.ReadInt64(numberSegment.Array, numberSegment.Offset, out _)); case JsonToken.String: return(reader.ReadString()); case JsonToken.True: return(reader.ReadBoolean()); // require advance case JsonToken.False: return(reader.ReadBoolean()); // require advance case JsonToken.ValueSeparator: case JsonToken.NameSeparator: case JsonToken.EndArray: case JsonToken.EndObject: throw new InvalidOperationException("Invalid Json Token:" + token); case JsonToken.Null: reader.ReadIsNull(); return(null); case JsonToken.None: default: return(null); } }