Represents a JSON constructor.
Inheritance: JContainer
 public void CreateWithMultiValue()
 {
     JConstructor constructor = new JConstructor("Test", new List<int> { 1, 2, 3 });
     Assert.AreEqual("Test", constructor.Name);
     Assert.AreEqual(3, constructor.Children().Count());
     Assert.AreEqual(1, (int)constructor.Children().ElementAt(0));
     Assert.AreEqual(2, (int)constructor.Children().ElementAt(1));
     Assert.AreEqual(3, (int)constructor.Children().ElementAt(2));
 }
 public void SetValueWithInvalidIndex()
 {
   ExceptionAssert.Throws<ArgumentException>(@"Set JConstructor values with invalid key value: ""badvalue"". Argument position index expected.",
   () =>
   {
     JConstructor c = new JConstructor();
     c["badvalue"] = new JValue(3);
   }); 
 }
    public void JConstructorDictionary()
    {
      Dictionary<JToken, int> dic = new Dictionary<JToken, int>(JToken.EqualityComparer);
      JConstructor v11 = new JConstructor("ConstructorValue");
      JConstructor v12 = new JConstructor("ConstructorValue");

      dic[v11] = 1;
      dic[v12] += 1;
      Assert.AreEqual(2, dic[v11]);
    }
示例#4
0
    public void SetValue()
    {
      object key = 0;

      JConstructor c = new JConstructor();
      c.Name = "con";
      c.Add(null);
      c[key] = new JValue(3);

      Assert.AreEqual(3, (int)c[key]);
    }
        public void Iterate()
        {
            JConstructor c = new JConstructor("MrConstructor", 1, 2, 3, 4, 5);

            int i = 1;
            foreach (JToken token in c)
            {
                Assert.AreEqual(i, (int)token);
                i++;
            }
        }
    public void EvaluateConstructorOutOfBoundsIndxerWithError()
    {
      JConstructor c = new JConstructor("Blah");

      c.SelectToken("[1]", true);
    }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JConstructor"/> class from another <see cref="JConstructor"/> object.
 /// </summary>
 /// <param name="other">A <see cref="JConstructor"/> object to copy from.</param>
 public JConstructor(JConstructor other)
     : base(other)
 {
     _name = other.Name;
 }
        internal void ReadContentFrom(JsonReader r)
        {
            JValue jValue;

            object[]    tokenType;
            CultureInfo invariantCulture;

            ValidationUtils.ArgumentNotNull(r, "r");
            IJsonLineInfo jsonLineInfo = r as IJsonLineInfo;
            JContainer    parent       = this;

            do
            {
                if (parent is JProperty && ((JProperty)parent).Value != null)
                {
                    if (parent == this)
                    {
                        return;
                    }
                    parent = parent.Parent;
                }
                switch (r.TokenType)
                {
                case JsonToken.None:
                {
                    continue;
                }

                case JsonToken.StartObject:
                {
                    JObject jObjects = new JObject();
                    jObjects.SetLineInfo(jsonLineInfo);
                    parent.Add(jObjects);
                    parent = jObjects;
                    continue;
                }

                case JsonToken.StartArray:
                {
                    JArray jArrays = new JArray();
                    jArrays.SetLineInfo(jsonLineInfo);
                    parent.Add(jArrays);
                    parent = jArrays;
                    continue;
                }

                case JsonToken.StartConstructor:
                {
                    JConstructor jConstructor = new JConstructor(r.Value.ToString());
                    jConstructor.SetLineInfo(jConstructor);
                    parent.Add(jConstructor);
                    parent = jConstructor;
                    continue;
                }

                case JsonToken.PropertyName:
                {
                    string    str       = r.Value.ToString();
                    JProperty jProperty = new JProperty(str);
                    jProperty.SetLineInfo(jsonLineInfo);
                    JProperty jProperty1 = ((JObject)parent).Property(str);
                    if (jProperty1 != null)
                    {
                        jProperty1.Replace(jProperty);
                    }
                    else
                    {
                        parent.Add(jProperty);
                    }
                    parent = jProperty;
                    continue;
                }

                case JsonToken.Comment:
                {
                    jValue = JValue.CreateComment(r.Value.ToString());
                    jValue.SetLineInfo(jsonLineInfo);
                    parent.Add(jValue);
                    continue;
                }

                case JsonToken.Raw:
                {
                    invariantCulture = CultureInfo.InvariantCulture;
                    tokenType        = new object[] { r.TokenType };
                    throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(invariantCulture, tokenType));
                }

                case JsonToken.Integer:
                case JsonToken.Float:
                case JsonToken.String:
                case JsonToken.Boolean:
                case JsonToken.Date:
                case JsonToken.Bytes:
                {
                    jValue = new JValue(r.Value);
                    jValue.SetLineInfo(jsonLineInfo);
                    parent.Add(jValue);
                    continue;
                }

                case JsonToken.Null:
                {
                    jValue = new JValue(null, JTokenType.Null);
                    jValue.SetLineInfo(jsonLineInfo);
                    parent.Add(jValue);
                    continue;
                }

                case JsonToken.Undefined:
                {
                    jValue = new JValue(null, JTokenType.Undefined);
                    jValue.SetLineInfo(jsonLineInfo);
                    parent.Add(jValue);
                    continue;
                }

                case JsonToken.EndObject:
                {
                    if (parent == this)
                    {
                        return;
                    }
                    parent = parent.Parent;
                    continue;
                }

                case JsonToken.EndArray:
                {
                    if (parent == this)
                    {
                        return;
                    }
                    parent = parent.Parent;
                    continue;
                }

                case JsonToken.EndConstructor:
                {
                    if (parent == this)
                    {
                        return;
                    }
                    parent = parent.Parent;
                    continue;
                }

                default:
                {
                    invariantCulture = CultureInfo.InvariantCulture;
                    tokenType        = new object[] { r.TokenType };
                    throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(invariantCulture, tokenType));
                }
                }
            }while (r.Read());
        }
示例#9
0
 public void JConstructorStringIndex()
 {
     JConstructor c = new JConstructor("ConstructorValue");
       Assert.AreEqual(null, c["purple"]);
 }
示例#10
0
    public void EvaluateIndexerOnConstructorWithError()
    {
      JConstructor c = new JConstructor("Blah");

      c.SelectToken("[1]", true);
    }
示例#11
0
 public void SetValueWithInvalidIndex()
 {
   JConstructor c = new JConstructor();
   c["badvalue"] = new JValue(3);
 }
示例#12
0
        private async Task ReadContentFromAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            IJsonLineInfo lineInfo = reader as IJsonLineInfo;

            JContainer parent = this;

            do
            {
                if ((parent as JProperty)?.Value != null)
                {
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                }

                switch (reader.TokenType)
                {
                case JsonToken.None:
                    // new reader. move to actual content
                    break;

                case JsonToken.StartArray:
                    JArray a = new JArray();
                    a.SetLineInfo(lineInfo, settings);
                    parent.Add(a);
                    parent = a;
                    break;

                case JsonToken.EndArray:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartObject:
                    JObject o = new JObject();
                    o.SetLineInfo(lineInfo, settings);
                    parent.Add(o);
                    parent = o;
                    break;

                case JsonToken.EndObject:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartConstructor:
                    JConstructor constructor = new JConstructor(reader.Value.ToString());
                    constructor.SetLineInfo(lineInfo, settings);
                    parent.Add(constructor);
                    parent = constructor;
                    break;

                case JsonToken.EndConstructor:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.String:
                case JsonToken.Integer:
                case JsonToken.Float:
                case JsonToken.Date:
                case JsonToken.Boolean:
                case JsonToken.Bytes:
                    JValue v = new JValue(reader.Value);
                    v.SetLineInfo(lineInfo, settings);
                    parent.Add(v);
                    break;

                case JsonToken.Comment:
                    if (settings != null && settings.CommentHandling == CommentHandling.Load)
                    {
                        v = JValue.CreateComment(reader.Value.ToString());
                        v.SetLineInfo(lineInfo, settings);
                        parent.Add(v);
                    }
                    break;

                case JsonToken.Null:
                    v = JValue.CreateNull();
                    v.SetLineInfo(lineInfo, settings);
                    parent.Add(v);
                    break;

                case JsonToken.Undefined:
                    v = JValue.CreateUndefined();
                    v.SetLineInfo(lineInfo, settings);
                    parent.Add(v);
                    break;

                case JsonToken.PropertyName:
                    string    propertyName = reader.Value.ToString();
                    JProperty property     = new JProperty(propertyName);
                    property.SetLineInfo(lineInfo, settings);
                    JObject parentObject = (JObject)parent;
                    // handle multiple properties with the same name in JSON
                    JProperty existingPropertyWithName = parentObject.Property(propertyName);
                    if (existingPropertyWithName == null)
                    {
                        parent.Add(property);
                    }
                    else
                    {
                        existingPropertyWithName.Replace(property);
                    }
                    parent = property;
                    break;

                default:
                    throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
                }
            } while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false));
        }
示例#13
0
        internal override bool DeepEquals(JToken node)
        {
            JConstructor c = node as JConstructor;

            return(c != null && _name == c.Name && ContentsEqual(c));
        }
示例#14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Newtonsoft.Json.Linq.JConstructor" /> class from another <see cref="T:Newtonsoft.Json.Linq.JConstructor" /> object.
 /// </summary>
 /// <param name="other">A <see cref="T:Newtonsoft.Json.Linq.JConstructor" /> object to copy from.</param>
 public JConstructor(JConstructor other)
     : base((JContainer)other)
 {
     this._name = other.Name;
 }
示例#15
0
 public JConstructor EchoJConstructor(JConstructor input)
 {
     return input;
 }
示例#16
0
 /// <summary>
 /// Loads an <see cref="T:Newtonsoft.Json.Linq.JConstructor" /> from a <see cref="T:Newtonsoft.Json.JsonReader" />.
 /// </summary>
 /// <param name="reader">A <see cref="T:Newtonsoft.Json.JsonReader" /> that will be read for the content of the <see cref="T:Newtonsoft.Json.Linq.JConstructor" />.</param>
 /// <returns>A <see cref="T:Newtonsoft.Json.Linq.JConstructor" /> that contains the JSON that was read from the specified <see cref="T:Newtonsoft.Json.JsonReader" />.</returns>
 public static JConstructor Load(JsonReader reader)
 {
     return(JConstructor.Load(reader, (JsonLoadSettings)null));
 }
示例#17
0
        internal void ReadContentFrom(JsonReader r)
        {
            ValidationUtils.ArgumentNotNull(r, "r");

            JContainer parent = this;

            do
            {
                if (parent is JProperty)
                {
                    if (((JProperty)parent).Value != null)
                    {
                        parent = parent.Parent;
                    }
                }

                switch (r.TokenType)
                {
                case JsonToken.None:
                    // new reader. move to actual content
                    break;

                case JsonToken.StartArray:
                    JArray a = new JArray();
                    parent.AddObjectSkipNotify(a);
                    parent = a;
                    break;

                case JsonToken.EndArray:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartObject:
                    JObject o = new JObject();
                    parent.AddObjectSkipNotify(o);
                    parent = o;
                    break;

                case JsonToken.EndObject:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartConstructor:
                    JConstructor constructor = new JConstructor();
                    constructor.Name = r.Value.ToString();
                    parent.AddObjectSkipNotify(constructor);
                    parent = constructor;
                    break;

                case JsonToken.EndConstructor:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.String:
                case JsonToken.Integer:
                case JsonToken.Float:
                case JsonToken.Date:
                case JsonToken.Boolean:
                    parent.AddObjectSkipNotify(new JValue(r.Value));
                    break;

                case JsonToken.Comment:
                    parent.AddObjectSkipNotify(JValue.CreateComment(r.Value.ToString()));
                    break;

                case JsonToken.Null:
                    parent.AddObjectSkipNotify(new JValue(null, JsonTokenType.Null));
                    break;

                case JsonToken.Undefined:
                    parent.AddObjectSkipNotify(new JValue(null, JsonTokenType.Undefined));
                    break;

                case JsonToken.PropertyName:
                    JProperty property = new JProperty(r.Value.ToString());
                    parent.AddObjectSkipNotify(property);
                    parent = property;
                    break;

                default:
                    throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(CultureInfo.InvariantCulture, r.TokenType));
                }
            }while (r.Read());
        }
示例#18
0
        internal void ReadContentFrom(JsonReader r)
        {
            ValidationUtils.ArgumentNotNull((object)r, "r");
            IJsonLineInfo lineInfo   = r as IJsonLineInfo;
            JContainer    jcontainer = this;

            do
            {
                if (jcontainer is JProperty && ((JProperty)jcontainer).Value != null)
                {
                    if (jcontainer == this)
                    {
                        break;
                    }
                    jcontainer = jcontainer.Parent;
                }
                switch (r.TokenType)
                {
                case JsonToken.None:
                    continue;

                case JsonToken.StartObject:
                    JObject jobject = new JObject();
                    jobject.SetLineInfo(lineInfo);
                    jcontainer.Add((object)jobject);
                    jcontainer = (JContainer)jobject;
                    goto case 0;

                case JsonToken.StartArray:
                    JArray jarray = new JArray();
                    jarray.SetLineInfo(lineInfo);
                    jcontainer.Add((object)jarray);
                    jcontainer = (JContainer)jarray;
                    goto case 0;

                case JsonToken.StartConstructor:
                    JConstructor jconstructor = new JConstructor(r.Value.ToString());
                    jconstructor.SetLineInfo((IJsonLineInfo)jconstructor);
                    jcontainer.Add((object)jconstructor);
                    jcontainer = (JContainer)jconstructor;
                    goto case 0;

                case JsonToken.PropertyName:
                    string    name       = r.Value.ToString();
                    JProperty jproperty1 = new JProperty(name);
                    jproperty1.SetLineInfo(lineInfo);
                    JProperty jproperty2 = ((JObject)jcontainer).Property(name);
                    if (jproperty2 == null)
                    {
                        jcontainer.Add((object)jproperty1);
                    }
                    else
                    {
                        jproperty2.Replace((JToken)jproperty1);
                    }
                    jcontainer = (JContainer)jproperty1;
                    goto case 0;

                case JsonToken.Comment:
                    JValue comment = JValue.CreateComment(r.Value.ToString());
                    comment.SetLineInfo(lineInfo);
                    jcontainer.Add((object)comment);
                    goto case 0;

                case JsonToken.Integer:
                case JsonToken.Float:
                case JsonToken.String:
                case JsonToken.Boolean:
                case JsonToken.Date:
                case JsonToken.Bytes:
                    JValue jvalue1 = new JValue(r.Value);
                    jvalue1.SetLineInfo(lineInfo);
                    jcontainer.Add((object)jvalue1);
                    goto case 0;

                case JsonToken.Null:
                    JValue jvalue2 = new JValue((object)null, JTokenType.Null);
                    jvalue2.SetLineInfo(lineInfo);
                    jcontainer.Add((object)jvalue2);
                    goto case 0;

                case JsonToken.Undefined:
                    JValue jvalue3 = new JValue((object)null, JTokenType.Undefined);
                    jvalue3.SetLineInfo(lineInfo);
                    jcontainer.Add((object)jvalue3);
                    goto case 0;

                case JsonToken.EndObject:
                    if (jcontainer == this)
                    {
                        return;
                    }
                    jcontainer = jcontainer.Parent;
                    goto case 0;

                case JsonToken.EndArray:
                    if (jcontainer == this)
                    {
                        return;
                    }
                    jcontainer = jcontainer.Parent;
                    goto case 0;

                case JsonToken.EndConstructor:
                    if (jcontainer == this)
                    {
                        return;
                    }
                    jcontainer = jcontainer.Parent;
                    goto case 0;

                default:
                    throw new InvalidOperationException(StringUtils.FormatWith("The JsonReader should not be on a token of type {0}.", (IFormatProvider)CultureInfo.InvariantCulture, (object)r.TokenType));
                }
            }while (r.Read());
        }
 public void JConstructorStringIndex()
 {
   ExceptionAssert.Throws<ArgumentException>(@"Accessed JConstructor values with invalid key value: ""purple"". Argument position index expected.",
   () =>
   {
     JConstructor c = new JConstructor("ConstructorValue");
     Assert.AreEqual(null, c["purple"]);
   });
 }
        internal void ReadContentFrom(JsonReader r, JsonLoadSettings settings)
        {
            JValue jValue;
            bool   value;

            ValidationUtils.ArgumentNotNull(r, "r");
            IJsonLineInfo jsonLineInfo = r as IJsonLineInfo;
            JContainer    parent       = this;

            do
            {
                JProperty jProperty = parent as JProperty;
                if (jProperty != null)
                {
                    value = jProperty.Value;
                }
                else
                {
                    value = false;
                }
                if (value)
                {
                    if (parent == this)
                    {
                        return;
                    }
                    parent = parent.Parent;
                }
                switch (r.TokenType)
                {
                case JsonToken.None:
                {
                    continue;
                }

                case JsonToken.StartObject:
                {
                    JObject jObjects = new JObject();
                    jObjects.SetLineInfo(jsonLineInfo, settings);
                    parent.Add(jObjects);
                    parent = jObjects;
                    continue;
                }

                case JsonToken.StartArray:
                {
                    JArray jArrays = new JArray();
                    jArrays.SetLineInfo(jsonLineInfo, settings);
                    parent.Add(jArrays);
                    parent = jArrays;
                    continue;
                }

                case JsonToken.StartConstructor:
                {
                    JConstructor jConstructor = new JConstructor(r.Value.ToString());
                    jConstructor.SetLineInfo(jsonLineInfo, settings);
                    parent.Add(jConstructor);
                    parent = jConstructor;
                    continue;
                }

                case JsonToken.PropertyName:
                {
                    string    str        = r.Value.ToString();
                    JProperty jProperty1 = new JProperty(str);
                    jProperty1.SetLineInfo(jsonLineInfo, settings);
                    JProperty jProperty2 = ((JObject)parent).Property(str);
                    if (jProperty2 != null)
                    {
                        jProperty2.Replace(jProperty1);
                    }
                    else
                    {
                        parent.Add(jProperty1);
                    }
                    parent = jProperty1;
                    continue;
                }

                case JsonToken.Comment:
                {
                    if (settings == null || settings.CommentHandling != CommentHandling.Load)
                    {
                        continue;
                    }
                    jValue = JValue.CreateComment(r.Value.ToString());
                    jValue.SetLineInfo(jsonLineInfo, settings);
                    parent.Add(jValue);
                    continue;
                }

                case JsonToken.Raw:
                {
                    throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(CultureInfo.InvariantCulture, r.TokenType));
                }

                case JsonToken.Integer:
                case JsonToken.Float:
                case JsonToken.String:
                case JsonToken.Boolean:
                case JsonToken.Date:
                case JsonToken.Bytes:
                {
                    jValue = new JValue(r.Value);
                    jValue.SetLineInfo(jsonLineInfo, settings);
                    parent.Add(jValue);
                    continue;
                }

                case JsonToken.Null:
                {
                    jValue = JValue.CreateNull();
                    jValue.SetLineInfo(jsonLineInfo, settings);
                    parent.Add(jValue);
                    continue;
                }

                case JsonToken.Undefined:
                {
                    jValue = JValue.CreateUndefined();
                    jValue.SetLineInfo(jsonLineInfo, settings);
                    parent.Add(jValue);
                    continue;
                }

                case JsonToken.EndObject:
                {
                    if (parent == this)
                    {
                        return;
                    }
                    parent = parent.Parent;
                    continue;
                }

                case JsonToken.EndArray:
                {
                    if (parent == this)
                    {
                        return;
                    }
                    parent = parent.Parent;
                    continue;
                }

                case JsonToken.EndConstructor:
                {
                    if (parent == this)
                    {
                        return;
                    }
                    parent = parent.Parent;
                    continue;
                }

                default:
                {
                    throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(CultureInfo.InvariantCulture, r.TokenType));
                }
                }
            }while (r.Read());
        }
示例#21
0
 public JConstructor(JConstructor other) : base(other)
 {
     this._values = new List <JToken>();
     this._name   = other.Name;
 }
示例#22
0
        private async Task ReadContentFromAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default)
        {
            IJsonLineInfo lineInfo = reader as IJsonLineInfo;

            JContainer parent = this;

            do
            {
                if (parent is JProperty p && p.Value != null)
                {
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                }

                MiscellaneousUtils.Assert(parent != null);

                switch (reader.TokenType)
                {
                case JsonToken.None:
                    // new reader. move to actual content
                    break;

                case JsonToken.StartArray:
                    JArray a = new JArray();
                    a.SetLineInfo(lineInfo, settings);
                    parent.Add(a);
                    parent = a;
                    break;

                case JsonToken.EndArray:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartObject:
                    JObject o = new JObject();
                    o.SetLineInfo(lineInfo, settings);
                    parent.Add(o);
                    parent = o;
                    break;

                case JsonToken.EndObject:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartConstructor:
                    JConstructor constructor = new JConstructor(reader.Value.ToString());
                    constructor.SetLineInfo(lineInfo, settings);
                    parent.Add(constructor);
                    parent = constructor;
                    break;

                case JsonToken.EndConstructor:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.String:
                case JsonToken.Integer:
                case JsonToken.Float:
                case JsonToken.Date:
                case JsonToken.Boolean:
                case JsonToken.Bytes:
                    JValue v = new JValue(reader.Value);
                    v.SetLineInfo(lineInfo, settings);
                    parent.Add(v);
                    break;

                case JsonToken.Comment:
                    if (settings != null && settings.CommentHandling == CommentHandling.Load)
                    {
                        v = JValue.CreateComment(reader.Value.ToString());
                        v.SetLineInfo(lineInfo, settings);
                        parent.Add(v);
                    }
                    break;

                case JsonToken.Null:
                    v = JValue.CreateNull();
                    v.SetLineInfo(lineInfo, settings);
                    parent.Add(v);
                    break;

                case JsonToken.Undefined:
                    v = JValue.CreateUndefined();
                    v.SetLineInfo(lineInfo, settings);
                    parent.Add(v);
                    break;

                case JsonToken.PropertyName:
                    JProperty property = ReadProperty(reader, settings, lineInfo, parent);
                    if (property != null)
                    {
                        parent = property;
                    }
                    else
                    {
                        await reader.SkipAsync().ConfigureAwait(false);
                    }
                    break;

                default:
                    throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
                }
            } while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false));
        }
示例#23
0
        internal void ReadContentFrom(JsonReader r)
        {
            ValidationUtils.ArgumentNotNull(r, "r");
            IJsonLineInfo lineInfo = r as IJsonLineInfo;

            JContainer parent = this;

            do
            {
                if (parent is JProperty && ((JProperty)parent).Value != null)
                {
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                }

                switch (r.TokenType)
                {
                case JsonToken.None:
                    // new reader. move to actual content
                    break;

                case JsonToken.StartArray:
                    JArray a = new JArray();
                    a.SetLineInfo(lineInfo);
                    parent.Add(a);
                    parent = a;
                    break;

                case JsonToken.EndArray:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartObject:
                    JObject o = new JObject();
                    o.SetLineInfo(lineInfo);
                    parent.Add(o);
                    parent = o;
                    break;

                case JsonToken.EndObject:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartConstructor:
                    JConstructor constructor = new JConstructor(r.Value.ToString());
                    constructor.SetLineInfo(constructor);
                    parent.Add(constructor);
                    parent = constructor;
                    break;

                case JsonToken.EndConstructor:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.String:
                case JsonToken.Integer:
                case JsonToken.Float:
                case JsonToken.Date:
                case JsonToken.Boolean:
                case JsonToken.Bytes:
                    JValue v = new JValue(r.Value);
                    v.SetLineInfo(lineInfo);
                    parent.Add(v);
                    break;

                case JsonToken.Comment:
                    v = JValue.CreateComment(r.Value.ToString());
                    v.SetLineInfo(lineInfo);
                    parent.Add(v);
                    break;

                case JsonToken.Null:
                    v = new JValue(null, JTokenType.Null);
                    v.SetLineInfo(lineInfo);
                    parent.Add(v);
                    break;

                case JsonToken.Undefined:
                    v = new JValue(null, JTokenType.Undefined);
                    v.SetLineInfo(lineInfo);
                    parent.Add(v);
                    break;

                case JsonToken.PropertyName:
                    string    propertyName = r.Value.ToString();
                    JProperty property     = new JProperty(propertyName);
                    property.SetLineInfo(lineInfo);
                    JObject parentObject = (JObject)parent;
                    // handle multiple properties with the same name in JSON
                    JProperty existingPropertyWithName = parentObject.Property(propertyName);
                    if (existingPropertyWithName == null)
                    {
                        parent.Add(property);
                    }
                    else
                    {
                        existingPropertyWithName.Replace(property);
                    }
                    parent = property;
                    break;

                default:
                    throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(CultureInfo.InvariantCulture, r.TokenType));
                }
            }while (r.Read());
        }
示例#24
0
 public static JConstructor Load(JsonReader reader)
 {
   if (reader.TokenType == JsonToken.None && !reader.Read())
     throw JsonReaderException.Create(reader, "Error reading JConstructor from JsonReader.");
   while (reader.TokenType == JsonToken.Comment)
     reader.Read();
   if (reader.TokenType != JsonToken.StartConstructor)
     throw JsonReaderException.Create(reader, StringUtils.FormatWith("Error reading JConstructor from JsonReader. Current JsonReader item is not a constructor: {0}", (IFormatProvider) CultureInfo.InvariantCulture, (object) reader.TokenType));
   JConstructor jconstructor = new JConstructor((string) reader.Value);
   jconstructor.SetLineInfo(reader as IJsonLineInfo);
   jconstructor.ReadTokenFrom(reader);
   return jconstructor;
 }
示例#25
0
        internal override bool DeepEquals(JToken node)
        {
            JConstructor container = node as JConstructor;

            return(((container != null) && (this._name == container.Name)) && base.ContentsEqual(container));
        }
示例#26
0
        public void MergeJConstructor()
        {
            JConstructor c1 = new JConstructor("c1", new[] { 1, 2 });
            JConstructor c2 = new JConstructor("c2", new[] { 3, 4 });

            c1.Merge(c2);
            Assert.AreEqual("c2", c1.Name);
            CollectionAssert.AreEquivalent(new[] { 1, 2, 3, 4 }, c1.Select(i => (int)i));

            JConstructor c3 = new JConstructor();
            c1.Merge(c3);
            Assert.AreEqual("c2", c1.Name);

            JConstructor c4 = new JConstructor("c4", new[] { 5, 6 });
            c1.Merge(c4, new JsonMergeSettings
            {
                MergeArrayHandling = MergeArrayHandling.Replace
            });
            Assert.AreEqual("c4", c1.Name);
            CollectionAssert.AreEquivalent(new[] { 5, 6 }, c1.Select(i => (int)i));
        }
示例#27
0
        internal void ReadContentFrom(JsonReader r)
        {
            ValidationUtils.ArgumentNotNull(r, "r");
            IJsonLineInfo lineInfo   = r as IJsonLineInfo;
            JContainer    jContainer = this;

            do
            {
                if (jContainer is JProperty && ((JProperty)jContainer).Value != null)
                {
                    if (jContainer == this)
                    {
                        break;
                    }
                    jContainer = jContainer.Parent;
                }
                switch (r.TokenType)
                {
                case JsonToken.StartArray:
                {
                    JArray jArray = new JArray();
                    jArray.SetLineInfo(lineInfo);
                    jContainer.Add(jArray);
                    jContainer = jArray;
                    break;
                }

                case JsonToken.EndArray:
                    if (jContainer == this)
                    {
                        return;
                    }
                    jContainer = jContainer.Parent;
                    break;

                case JsonToken.StartObject:
                {
                    JObject jObject2 = new JObject();
                    jObject2.SetLineInfo(lineInfo);
                    jContainer.Add(jObject2);
                    jContainer = jObject2;
                    break;
                }

                case JsonToken.EndObject:
                    if (jContainer == this)
                    {
                        return;
                    }
                    jContainer = jContainer.Parent;
                    break;

                case JsonToken.StartConstructor:
                {
                    JConstructor jConstructor = new JConstructor(r.Value.ToString());
                    jConstructor.SetLineInfo(jConstructor);
                    jContainer.Add(jConstructor);
                    jContainer = jConstructor;
                    break;
                }

                case JsonToken.EndConstructor:
                    if (jContainer == this)
                    {
                        return;
                    }
                    jContainer = jContainer.Parent;
                    break;

                case JsonToken.Integer:
                case JsonToken.Float:
                case JsonToken.String:
                case JsonToken.Boolean:
                case JsonToken.Date:
                case JsonToken.Bytes:
                {
                    JValue jValue = new JValue(r.Value);
                    jValue.SetLineInfo(lineInfo);
                    jContainer.Add(jValue);
                    break;
                }

                case JsonToken.Comment:
                {
                    JValue jValue = JValue.CreateComment(r.Value.ToString());
                    jValue.SetLineInfo(lineInfo);
                    jContainer.Add(jValue);
                    break;
                }

                case JsonToken.Null:
                {
                    JValue jValue = new JValue(null, JTokenType.Null);
                    jValue.SetLineInfo(lineInfo);
                    jContainer.Add(jValue);
                    break;
                }

                case JsonToken.Undefined:
                {
                    JValue jValue = new JValue(null, JTokenType.Undefined);
                    jValue.SetLineInfo(lineInfo);
                    jContainer.Add(jValue);
                    break;
                }

                case JsonToken.PropertyName:
                {
                    string    name      = r.Value.ToString();
                    JProperty jProperty = new JProperty(name);
                    jProperty.SetLineInfo(lineInfo);
                    JObject   jObject    = (JObject)jContainer;
                    JProperty jProperty2 = jObject.Property(name);
                    if (jProperty2 == null)
                    {
                        jContainer.Add(jProperty);
                    }
                    else
                    {
                        jProperty2.Replace(jProperty);
                    }
                    jContainer = jProperty;
                    break;
                }

                default:
                    throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(CultureInfo.InvariantCulture, r.TokenType));

                case JsonToken.None:
                    break;
                }
            }while (r.Read());
        }
示例#28
0
        /// <summary>
        /// Asynchronously creates a <see cref="JToken"/> from a <see cref="JsonReader"/>.
        /// </summary>
        /// <param name="reader">An <see cref="JsonReader"/> positioned at the token to read into this <see cref="JToken"/>.</param>
        /// <param name="settings">The <see cref="JsonLoadSettings"/> used to load the JSON.
        /// If this is <c>null</c>, default load settings will be used.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns>
        /// A <see cref="Task{TResult}"/> that represents the asynchronous creation. The
        /// <see cref="Task{TResult}.Result"/> property returns a <see cref="JToken"/> that contains
        /// the token and its descendant tokens
        /// that were read from the reader. The runtime type of the token is determined
        /// by the token type of the first token encountered in the reader.
        /// </returns>
        public static async Task <JToken> ReadFromAsync(JsonReader reader, JsonLoadSettings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            ValidationUtils.ArgumentNotNull(reader, nameof(reader));

            if (reader.TokenType == JsonToken.None)
            {
                if (!await(settings != null && settings.CommentHandling == CommentHandling.Ignore ? reader.ReadAndMoveToContentAsync(cancellationToken) : reader.ReadAsync(cancellationToken)).ConfigureAwait(false))
                {
                    throw JsonReaderException.Create(reader, "Error reading JToken from JsonReader.");
                }
            }

            IJsonLineInfo lineInfo = reader as IJsonLineInfo;

            switch (reader.TokenType)
            {
            case JsonToken.StartObject:
                return(await JObject.LoadAsync(reader, settings, cancellationToken).ConfigureAwait(false));

            case JsonToken.StartArray:
                return(await JArray.LoadAsync(reader, settings, cancellationToken).ConfigureAwait(false));

            case JsonToken.StartConstructor:
                return(await JConstructor.LoadAsync(reader, settings, cancellationToken).ConfigureAwait(false));

            case JsonToken.PropertyName:
                return(await JProperty.LoadAsync(reader, settings, cancellationToken).ConfigureAwait(false));

            case JsonToken.String:
            case JsonToken.Integer:
            case JsonToken.Float:
            case JsonToken.Date:
            case JsonToken.Boolean:
            case JsonToken.Bytes:
                JValue v = new JValue(reader.Value);
                v.SetLineInfo(lineInfo, settings);
                return(v);

            case JsonToken.Comment:
                v = JValue.CreateComment(reader.Value.ToString());
                v.SetLineInfo(lineInfo, settings);
                return(v);

            case JsonToken.Null:
                v = JValue.CreateNull();
                v.SetLineInfo(lineInfo, settings);
                return(v);

            case JsonToken.Undefined:
                v = JValue.CreateUndefined();
                v.SetLineInfo(lineInfo, settings);
                return(v);

            case JsonToken.SmallDec:
            case JsonToken.PercentValV2:
                try
                {
                    v = new JValue(reader.Value);
                    v.SetLineInfo(lineInfo, settings);
                    return(v);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("Exception called from JToken.Async->ReadContentFromAsync of type " + ex.ToString());
                    throw;
                }

            default:
                throw JsonReaderException.Create(reader, "Error reading JToken from JsonReader. Unexpected token: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
            }
        }
示例#29
0
 public JConstructor(JConstructor other) : base(other)
 {
     this.list_0   = new List <JToken>();
     this.string_0 = other.Name;
 }
示例#30
0
        internal JToken Evaluate(JToken root, bool errorWhenNoMatch)
        {
            JToken current = root;

            foreach (object part in Parts)
            {
                string propertyName = part as string;
                if (propertyName != null)
                {
                    JObject o = current as JObject;
                    if (o != null)
                    {
                        current = o[propertyName];

                        if (current == null && errorWhenNoMatch)
                        {
                            throw new JsonException("Property '{0}' does not exist on JObject.".FormatWith(CultureInfo.InvariantCulture, propertyName));
                        }
                    }
                    else
                    {
                        if (errorWhenNoMatch)
                        {
                            throw new JsonException("Property '{0}' not valid on {1}.".FormatWith(CultureInfo.InvariantCulture, propertyName, current.GetType().Name));
                        }

                        return(null);
                    }
                }
                else
                {
                    int index = (int)part;

                    JArray       a = current as JArray;
                    JConstructor c = current as JConstructor;

                    if (a != null)
                    {
                        if (a.Count <= index)
                        {
                            if (errorWhenNoMatch)
                            {
                                throw new JsonException("Index {0} outside the bounds of JArray.".FormatWith(CultureInfo.InvariantCulture, index));
                            }

                            return(null);
                        }

                        current = a[index];
                    }
                    else if (c != null)
                    {
                        if (c.Count <= index)
                        {
                            if (errorWhenNoMatch)
                            {
                                throw new JsonException("Index {0} outside the bounds of JConstructor.".FormatWith(CultureInfo.InvariantCulture, index));
                            }

                            return(null);
                        }

                        current = c[index];
                    }
                    else
                    {
                        if (errorWhenNoMatch)
                        {
                            throw new JsonException("Index {0} not valid on {1}.".FormatWith(CultureInfo.InvariantCulture, index, current.GetType().Name));
                        }

                        return(null);
                    }
                }
            }

            return(current);
        }
示例#31
0
 public JConstructor(JConstructor other)
   : base((JContainer) other)
 {
   this._name = other.Name;
 }
示例#32
0
 // Token: 0x06001236 RID: 4662 RVA: 0x00063D40 File Offset: 0x00061F40
 public new static JConstructor Load(JsonReader reader)
 {
     return(JConstructor.Load(reader, null));
 }
示例#33
0
        public void MergeNull()
        {
            JConstructor c = new JConstructor();
            c.Merge(null);
            Assert.AreEqual(null, c.Name);
            Assert.AreEqual(0, c.Count);

            JObject o = new JObject();
            o.Merge(null);
            Assert.AreEqual(0, o.Count);

            JArray a = new JArray();
            a.Merge(null);
            Assert.AreEqual(0, a.Count);

            JProperty p = new JProperty("name1");
            p.Merge(null);
            Assert.AreEqual("name1", p.Name);
            Assert.AreEqual(0, p.Count);
        }
示例#34
0
        internal void ReadContentFrom(JsonReader r)
        {
            ValidationUtils.ArgumentNotNull(r, "r");
            IJsonLineInfo lineInfo   = r as IJsonLineInfo;
            JContainer    jcontainer = this;

            for (;;)
            {
                if (jcontainer is JProperty && ((JProperty)jcontainer).Value != null)
                {
                    if (jcontainer == this)
                    {
                        break;
                    }
                    jcontainer = jcontainer.Parent;
                }
                switch (r.TokenType)
                {
                case JsonToken.None:
                    goto IL_244;

                case JsonToken.StartObject:
                {
                    JObject jobject = new JObject();
                    jobject.SetLineInfo(lineInfo);
                    jcontainer.Add(jobject);
                    jcontainer = jobject;
                    goto IL_244;
                }

                case JsonToken.StartArray:
                {
                    JArray jarray = new JArray();
                    jarray.SetLineInfo(lineInfo);
                    jcontainer.Add(jarray);
                    jcontainer = jarray;
                    goto IL_244;
                }

                case JsonToken.StartConstructor:
                {
                    JConstructor jconstructor = new JConstructor(r.Value.ToString());
                    jconstructor.SetLineInfo(jconstructor);
                    jcontainer.Add(jconstructor);
                    jcontainer = jconstructor;
                    goto IL_244;
                }

                case JsonToken.PropertyName:
                {
                    string    name      = r.Value.ToString();
                    JProperty jproperty = new JProperty(name);
                    jproperty.SetLineInfo(lineInfo);
                    JObject   jobject2   = (JObject)jcontainer;
                    JProperty jproperty2 = jobject2.Property(name);
                    if (jproperty2 == null)
                    {
                        jcontainer.Add(jproperty);
                    }
                    else
                    {
                        jproperty2.Replace(jproperty);
                    }
                    jcontainer = jproperty;
                    goto IL_244;
                }

                case JsonToken.Comment:
                {
                    JValue jvalue = JValue.CreateComment(r.Value.ToString());
                    jvalue.SetLineInfo(lineInfo);
                    jcontainer.Add(jvalue);
                    goto IL_244;
                }

                case JsonToken.Integer:
                case JsonToken.Float:
                case JsonToken.String:
                case JsonToken.Boolean:
                case JsonToken.Date:
                case JsonToken.Bytes:
                {
                    JValue jvalue = new JValue(r.Value);
                    jvalue.SetLineInfo(lineInfo);
                    jcontainer.Add(jvalue);
                    goto IL_244;
                }

                case JsonToken.Null:
                {
                    JValue jvalue = new JValue(null, JTokenType.Null);
                    jvalue.SetLineInfo(lineInfo);
                    jcontainer.Add(jvalue);
                    goto IL_244;
                }

                case JsonToken.Undefined:
                {
                    JValue jvalue = new JValue(null, JTokenType.Undefined);
                    jvalue.SetLineInfo(lineInfo);
                    jcontainer.Add(jvalue);
                    goto IL_244;
                }

                case JsonToken.EndObject:
                    if (jcontainer == this)
                    {
                        return;
                    }
                    jcontainer = jcontainer.Parent;
                    goto IL_244;

                case JsonToken.EndArray:
                    if (jcontainer == this)
                    {
                        return;
                    }
                    jcontainer = jcontainer.Parent;
                    goto IL_244;

                case JsonToken.EndConstructor:
                    if (jcontainer == this)
                    {
                        return;
                    }
                    jcontainer = jcontainer.Parent;
                    goto IL_244;
                }
                goto Block_4;
IL_244:
                if (!r.Read())
                {
                    return;
                }
            }
            return;

Block_4:
            throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(CultureInfo.InvariantCulture, new object[]
            {
                r.TokenType
            }));
        }
示例#35
0
        /// <summary>
        /// Loads an <see cref="JConstructor"/> from a <see cref="JsonReader"/>. 
        /// </summary>
        /// <param name="reader">A <see cref="JsonReader"/> that will be read for the content of the <see cref="JConstructor"/>.</param>
        /// <param name="settings">The <see cref="JsonLoadSettings"/> used to load the JSON.
        /// If this is null, default load settings will be used.</param>
        /// <returns>A <see cref="JConstructor"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
        public new static JConstructor Load(JsonReader reader, JsonLoadSettings settings)
        {
            if (reader.TokenType == JsonToken.None)
            {
                if (!reader.Read())
                    throw JsonReaderException.Create(reader, "Error reading JConstructor from JsonReader.");
            }

            while (reader.TokenType == JsonToken.Comment)
            {
                reader.Read();
            }

            if (reader.TokenType != JsonToken.StartConstructor)
                throw JsonReaderException.Create(reader, "Error reading JConstructor from JsonReader. Current JsonReader item is not a constructor: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));

            JConstructor c = new JConstructor((string)reader.Value);
            c.SetLineInfo(reader as IJsonLineInfo);

            c.ReadTokenFrom(reader, settings);

            return c;
        }
示例#36
0
        internal override bool DeepEquals(JToken node)
        {
            JConstructor jConstructor = node as JConstructor;

            return(jConstructor != null && this._name == jConstructor.Name && base.ContentsEqual(jConstructor));
        }
示例#37
0
        /// <summary>
        /// Loads an <see cref="JConstructor"/> from a <see cref="JsonReader"/>. 
        /// </summary>
        /// <param name="reader">A <see cref="JsonReader"/> that will be read for the content of the <see cref="JConstructor"/>.</param>
        /// <returns>A <see cref="JConstructor"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
        public static new JConstructor Load(JsonReader reader)
        {
            if (reader.TokenType == JsonToken.None)
            {
            if (!reader.Read())
            throw new Exception("Error reading JConstructor from JsonReader.");
            }

            if (reader.TokenType != JsonToken.StartConstructor)
            throw new Exception("Error reading JConstructor from JsonReader. Current JsonReader item is not a constructor: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));

            JConstructor c = new JConstructor((string)reader.Value);
            c.SetLineInfo(reader as IJsonLineInfo);

            c.ReadTokenFrom(reader);

            return c;
        }
示例#38
0
文件: JPath.cs 项目: conankzhang/fez
        internal JToken Evaluate(JToken root, bool errorWhenNoMatch)
        {
            JToken jtoken = root;

            foreach (object obj in this.Parts)
            {
                string index1 = obj as string;
                if (index1 != null)
                {
                    JObject jobject = jtoken as JObject;
                    if (jobject != null)
                    {
                        jtoken = jobject[index1];
                        if (jtoken == null && errorWhenNoMatch)
                        {
                            throw new JsonException(StringUtils.FormatWith("Property '{0}' does not exist on JObject.", (IFormatProvider)CultureInfo.InvariantCulture, (object)index1));
                        }
                    }
                    else if (errorWhenNoMatch)
                    {
                        throw new JsonException(StringUtils.FormatWith("Property '{0}' not valid on {1}.", (IFormatProvider)CultureInfo.InvariantCulture, (object)index1, (object)jtoken.GetType().Name));
                    }
                    else
                    {
                        return((JToken)null);
                    }
                }
                else
                {
                    int          index2       = (int)obj;
                    JArray       jarray       = jtoken as JArray;
                    JConstructor jconstructor = jtoken as JConstructor;
                    if (jarray != null)
                    {
                        if (jarray.Count <= index2)
                        {
                            if (errorWhenNoMatch)
                            {
                                throw new IndexOutOfRangeException(StringUtils.FormatWith("Index {0} outside the bounds of JArray.", (IFormatProvider)CultureInfo.InvariantCulture, (object)index2));
                            }
                            else
                            {
                                return((JToken)null);
                            }
                        }
                        else
                        {
                            jtoken = jarray[index2];
                        }
                    }
                    else if (jconstructor != null)
                    {
                        if (jconstructor.Count <= index2)
                        {
                            if (errorWhenNoMatch)
                            {
                                throw new IndexOutOfRangeException(StringUtils.FormatWith("Index {0} outside the bounds of JConstructor.", (IFormatProvider)CultureInfo.InvariantCulture, (object)index2));
                            }
                            else
                            {
                                return((JToken)null);
                            }
                        }
                        else
                        {
                            jtoken = jconstructor[(object)index2];
                        }
                    }
                    else if (errorWhenNoMatch)
                    {
                        throw new JsonException(StringUtils.FormatWith("Index {0} not valid on {1}.", (IFormatProvider)CultureInfo.InvariantCulture, (object)index2, (object)jtoken.GetType().Name));
                    }
                    else
                    {
                        return((JToken)null);
                    }
                }
            }
            return(jtoken);
        }
        public void EvaluateConstructorOutOfBoundsIndxer()
        {
            JConstructor c = new JConstructor("Blah");

            Assert.IsNull(c.SelectToken("[1]"));
        }
示例#40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JConstructor"/> class from another <see cref="JConstructor"/> object.
 /// </summary>
 /// <param name="other">A <see cref="JConstructor"/> object to copy from.</param>
 public JConstructor(JConstructor other)
     : base(other)
 {
     _name = other.Name;
 }
示例#41
0
    public void EvaluateConstructorOutOfBoundsIndxerWithError()
    {
      JConstructor c = new JConstructor("Blah");

      ExceptionAssert.Throws<IndexOutOfRangeException>(
        @"Index 1 outside the bounds of JConstructor.",
        () =>
        {
          c.SelectToken("[1]", true);
        });
    }
示例#42
0
        internal void ReadContentFrom(JsonReader r, JsonLoadSettings settings)
        {
            JProperty property1;
            JValue    value2;
            JProperty property;

            ValidationUtils.ArgumentNotNull(r, "r");
            IJsonLineInfo lineInfo = r as IJsonLineInfo;
            JContainer    parent   = this;

Label_0014:
            property1 = parent as JProperty;
            if (property1 == null)
            {
            }
            if (null.Value != null)
            {
                if (parent == this)
                {
                    return;
                }
                parent = parent.Parent;
            }
            switch (r.TokenType)
            {
            case JsonToken.None:
                goto Label_0247;

            case JsonToken.StartObject:
            {
                JObject content = new JObject();
                content.SetLineInfo(lineInfo, settings);
                parent.Add(content);
                parent = content;
                goto Label_0247;
            }

            case JsonToken.StartArray:
            {
                JArray content = new JArray();
                content.SetLineInfo(lineInfo, settings);
                parent.Add(content);
                parent = content;
                goto Label_0247;
            }

            case JsonToken.StartConstructor:
            {
                JConstructor content = new JConstructor(r.Value.ToString());
                content.SetLineInfo(lineInfo, settings);
                parent.Add(content);
                parent = content;
                goto Label_0247;
            }

            case JsonToken.PropertyName:
            {
                string name = r.Value.ToString();
                property = new JProperty(name);
                property.SetLineInfo(lineInfo, settings);
                JProperty property2 = ((JObject)parent).Property(name);
                if (property2 != null)
                {
                    property2.Replace(property);
                    break;
                }
                parent.Add(property);
                break;
            }

            case JsonToken.Comment:
                if ((settings != null) && (settings.CommentHandling == CommentHandling.Load))
                {
                    value2 = JValue.CreateComment(r.Value.ToString());
                    value2.SetLineInfo(lineInfo, settings);
                    parent.Add(value2);
                }
                goto Label_0247;

            case JsonToken.Integer:
            case JsonToken.Float:
            case JsonToken.String:
            case JsonToken.Boolean:
            case JsonToken.Date:
            case JsonToken.Bytes:
                value2 = new JValue(r.Value);
                value2.SetLineInfo(lineInfo, settings);
                parent.Add(value2);
                goto Label_0247;

            case JsonToken.Null:
                value2 = JValue.CreateNull();
                value2.SetLineInfo(lineInfo, settings);
                parent.Add(value2);
                goto Label_0247;

            case JsonToken.Undefined:
                value2 = JValue.CreateUndefined();
                value2.SetLineInfo(lineInfo, settings);
                parent.Add(value2);
                goto Label_0247;

            case JsonToken.EndObject:
                if (parent != this)
                {
                    parent = parent.Parent;
                    goto Label_0247;
                }
                return;

            case JsonToken.EndArray:
                if (parent != this)
                {
                    parent = parent.Parent;
                    goto Label_0247;
                }
                return;

            case JsonToken.EndConstructor:
                if (parent != this)
                {
                    parent = parent.Parent;
                    goto Label_0247;
                }
                return;

            default:
                throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(CultureInfo.InvariantCulture, r.TokenType));
            }
            parent = property;
Label_0247:
            if (r.Read())
            {
                goto Label_0014;
            }
        }