Пример #1
0
        /// <summary>
        /// Parses the value.
        /// </summary>
        /// <param name="asDictionaryKey">If set to <c>true</c> [as dictionary key].</param>
        /// <param name="cache">The cache.</param>
        /// <returns>
        /// The parsed value.
        /// </returns>
        public override object ParseVal(bool asDictionaryKey, ReadCache cache)
        {
            switch (jp.TokenType)
            {
            case JsonToken.Integer:
                return(ParseLong());

            case JsonToken.StartArray:
                return(ParseList(asDictionaryKey, cache, null));

            case JsonToken.StartObject:
                return(ParseDictionary(asDictionaryKey, cache, null));

            case JsonToken.PropertyName:
            case JsonToken.String:
                return(cache.CacheRead((string)jp.Value, asDictionaryKey, this));

            case JsonToken.Float:
            case JsonToken.Boolean:
                return(jp.Value);

            case JsonToken.Null:
                return(null);

            case JsonToken.Bytes:
            case JsonToken.Comment:
            case JsonToken.Date:
            case JsonToken.EndArray:
            case JsonToken.EndConstructor:
            case JsonToken.EndObject:
            case JsonToken.None:
            case JsonToken.Raw:
            case JsonToken.StartConstructor:
            case JsonToken.Undefined:

            default:
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// Parses the value.
        /// </summary>
        /// <param name="asDictionaryKey">If set to <c>true</c> [as dictionary key].</param>
        /// <param name="cache">The cache.</param>
        /// <returns>
        /// The parsed value.
        /// </returns>
        public override object ParseVal(bool asDictionaryKey, ReadCache cache)
        {
            switch (jp.TokenType)
            {
                case JsonToken.Integer:
                    return ParseLong();
                case JsonToken.StartArray:
                    return ParseList(asDictionaryKey, cache, null);
                case JsonToken.StartObject:
                    return ParseDictionary(asDictionaryKey, cache, null);
                case JsonToken.PropertyName:
                case JsonToken.String:
                    return cache.CacheRead((string)jp.Value, asDictionaryKey, this);
                case JsonToken.Float:
                case JsonToken.Boolean:
                    return jp.Value;
                case JsonToken.Null:
                    return null;

                case JsonToken.Bytes:
                case JsonToken.Comment:
                case JsonToken.Date:
                case JsonToken.EndArray:
                case JsonToken.EndConstructor:
                case JsonToken.EndObject:
                case JsonToken.None:
                case JsonToken.Raw:
                case JsonToken.StartConstructor:
                case JsonToken.Undefined:

                default:
                    return null;
            }
        }
Пример #3
0
 public void TestReadCache()
 {
     ReadCache rc = new ReadCache();
     Assert.AreEqual("~:foo", rc.CacheRead("~:foo", false));
     Assert.AreEqual("~:foo", rc.CacheRead("^" + (char)WriteCache.BaseCharIdx, false));
     Assert.AreEqual("~$bar", rc.CacheRead("~$bar", false));
     Assert.AreEqual("~$bar", rc.CacheRead("^" + (char)(WriteCache.BaseCharIdx + 1), false));
     Assert.AreEqual("~#baz", rc.CacheRead("~#baz", false));
     Assert.AreEqual("~#baz", rc.CacheRead("^" + (char)(WriteCache.BaseCharIdx + 2), false));
     Assert.AreEqual("foobar", rc.CacheRead("foobar", false));
     Assert.AreEqual("foobar", rc.CacheRead("foobar", false));
     Assert.AreEqual("foobar", rc.CacheRead("foobar", true));
     Assert.AreEqual("foobar", rc.CacheRead("^" + (char)(WriteCache.BaseCharIdx + 3), true));
     Assert.AreEqual("abc", rc.CacheRead("abc", false));
     Assert.AreEqual("abc", rc.CacheRead("abc", false));
     Assert.AreEqual("abc", rc.CacheRead("abc", true));
     Assert.AreEqual("abc", rc.CacheRead("abc", true));
 }