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(lineInfo); 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 = JValue.CreateNull(); v.SetLineInfo(lineInfo); parent.Add(v); break; case JsonToken.Undefined: v = JValue.CreateUndefined(); 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()); }
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; } }
internal void ReadContentFrom(JsonReader r, JsonLoadSettings settings) { ValidationUtils.ArgumentNotNull((object)r, nameof(r)); IJsonLineInfo lineInfo = r as IJsonLineInfo; JContainer jcontainer = this; do { if ((jcontainer is JProperty jproperty ? jproperty.Value : (JToken)null) != 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, settings); jcontainer.Add((object)jobject); jcontainer = (JContainer)jobject; goto case JsonToken.None; case JsonToken.StartArray: JArray jarray = new JArray(); jarray.SetLineInfo(lineInfo, settings); jcontainer.Add((object)jarray); jcontainer = (JContainer)jarray; goto case JsonToken.None; case JsonToken.StartConstructor: JConstructor jconstructor = new JConstructor(r.Value.ToString()); jconstructor.SetLineInfo(lineInfo, settings); jcontainer.Add((object)jconstructor); jcontainer = (JContainer)jconstructor; goto case JsonToken.None; case JsonToken.PropertyName: string name = r.Value.ToString(); JProperty jproperty1 = new JProperty(name); jproperty1.SetLineInfo(lineInfo, settings); JProperty jproperty2 = ((JObject)jcontainer).Property(name); if (jproperty2 == null) { jcontainer.Add((object)jproperty1); } else { jproperty2.Replace((JToken)jproperty1); } jcontainer = (JContainer)jproperty1; goto case JsonToken.None; case JsonToken.Comment: if (settings != null && settings.CommentHandling == CommentHandling.Load) { JValue comment = JValue.CreateComment(r.Value.ToString()); comment.SetLineInfo(lineInfo, settings); jcontainer.Add((object)comment); goto case JsonToken.None; } else { goto case JsonToken.None; } 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, settings); jcontainer.Add((object)jvalue1); goto case JsonToken.None; case JsonToken.Null: JValue jvalue2 = JValue.CreateNull(); jvalue2.SetLineInfo(lineInfo, settings); jcontainer.Add((object)jvalue2); goto case JsonToken.None; case JsonToken.Undefined: JValue undefined = JValue.CreateUndefined(); undefined.SetLineInfo(lineInfo, settings); jcontainer.Add((object)undefined); goto case JsonToken.None; case JsonToken.EndObject: if (jcontainer == this) { return; } jcontainer = jcontainer.Parent; goto case JsonToken.None; case JsonToken.EndArray: if (jcontainer == this) { return; } jcontainer = jcontainer.Parent; goto case JsonToken.None; case JsonToken.EndConstructor: if (jcontainer == this) { return; } jcontainer = jcontainer.Parent; goto case JsonToken.None; default: throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith((IFormatProvider)CultureInfo.InvariantCulture, (object)r.TokenType)); } }while (r.Read()); }
internal void ReadContentFrom(JsonReader r) { ValidationUtils.ArgumentNotNull(r, "r"); IJsonLineInfo lineInfo = r as IJsonLineInfo; JContainer jContainer = this; while (true) { if (jContainer is JProperty && ((JProperty)jContainer).Value != null) { if (jContainer == this) { break; } jContainer = jContainer.Parent; } switch (r.TokenType) { case JsonToken.None: goto IL_236; case JsonToken.StartObject: { JObject jObject = new JObject(); jObject.SetLineInfo(lineInfo); jContainer.Add(jObject); jContainer = jObject; goto IL_236; } case JsonToken.StartArray: { JArray jArray = new JArray(); jArray.SetLineInfo(lineInfo); jContainer.Add(jArray); jContainer = jArray; goto IL_236; } case JsonToken.StartConstructor: { JConstructor jConstructor = new JConstructor(r.Value.ToString()); jConstructor.SetLineInfo(jConstructor); jContainer.Add(jConstructor); jContainer = jConstructor; goto IL_236; } 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_236; } case JsonToken.Comment: { JValue jValue = JValue.CreateComment(r.Value.ToString()); jValue.SetLineInfo(lineInfo); jContainer.Add(jValue); goto IL_236; } 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_236; } case JsonToken.Null: { JValue jValue = new JValue(null, JTokenType.Null); jValue.SetLineInfo(lineInfo); jContainer.Add(jValue); goto IL_236; } case JsonToken.Undefined: { JValue jValue = new JValue(null, JTokenType.Undefined); jValue.SetLineInfo(lineInfo); jContainer.Add(jValue); goto IL_236; } case JsonToken.EndObject: if (jContainer == this) { return; } jContainer = jContainer.Parent; goto IL_236; case JsonToken.EndArray: if (jContainer == this) { return; } jContainer = jContainer.Parent; goto IL_236; case JsonToken.EndConstructor: if (jContainer == this) { return; } jContainer = jContainer.Parent; goto IL_236; } goto Block_4; IL_236: if (!r.Read()) { return; } } return; Block_4: throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(CultureInfo.InvariantCulture, r.TokenType)); }