WriteToken() приватный Метод

private WriteToken ( JsonReader reader, bool writeChildren, bool writeDateConstructorAsDate, bool writeComments ) : void
reader JsonReader
writeChildren bool
writeDateConstructorAsDate bool
writeComments bool
Результат void
    private JToken CreateJToken(JsonReader reader, JsonContract contract)
    {
      ValidationUtils.ArgumentNotNull(reader, "reader");

      if (contract != null && contract.UnderlyingType == typeof (JRaw))
      {
        return JRaw.Create(reader);
      }
      else
      {
        JToken token;
        using (JTokenWriter writer = new JTokenWriter())
        {
          writer.WriteToken(reader);
          token = writer.Token;
        }

        return token;
      }
    }
    private JToken CreateJObject(JsonReader reader)
    {
      ValidationUtils.ArgumentNotNull(reader, "reader");

      // this is needed because we've already read inside the object, looking for special properties
      JToken token;
      using (JTokenWriter writer = new JTokenWriter())
      {
        writer.WriteStartObject();

        if (reader.TokenType == JsonToken.PropertyName)
          writer.WriteToken(reader, reader.Depth - 1);
        else
          writer.WriteEndObject();

        token = writer.Token;
      }

      return token;
    }
        private JToken CreateJToken(JsonReader reader, JsonContract contract)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");

            if (contract != null)
            {
                if (contract.UnderlyingType == typeof(JRaw))
                    return JRaw.Create(reader);
                if (reader.TokenType == JsonToken.Null
                    && !(contract.UnderlyingType == typeof(JValue) || contract.UnderlyingType == typeof(JToken)))
                    return null;
            }

            JToken token;
            using (JTokenWriter writer = new JTokenWriter())
            {
                writer.WriteToken(reader);
                token = writer.Token;
            }

            return token;
        }
        private JToken CreateJObject(JsonReader reader)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");

            // this is needed because we've already read inside the object, looking for metadata properties
            using (JTokenWriter writer = new JTokenWriter())
            {
                writer.WriteStartObject();

                do
                {
                    if (reader.TokenType == JsonToken.PropertyName)
                    {
                        string propertyName = (string)reader.Value;
                        do
                        {
                            if (!reader.Read())
                                break;
                        } while (reader.TokenType == JsonToken.Comment);

                        if (CheckPropertyName(reader, propertyName))
                            continue;

                        writer.WritePropertyName(propertyName);
                        writer.WriteToken(reader, true, true);
                    }
                    else if (reader.TokenType == JsonToken.Comment)
                    {
                        // eat
                    }
                    else
                    {
                        writer.WriteEndObject();
                        return writer.Token;
                    }
                } while (reader.Read());

                throw JsonSerializationException.Create(reader, "Unexpected end when deserializing object.");
            }
        }
Пример #5
0
        public void WriteValueTokenWithParent()
        {
            JValue v = new JValue(1);

            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartArray();

            writer.WriteToken(v.CreateReader());

            Assert.AreEqual(WriteState.Array, writer.WriteState);

            writer.WriteEndArray();

            StringAssert.AreEqual(@"[
  1
]", writer.Token.ToString());
        }
Пример #6
0
        public void WriteEmptyToken()
        {
            JObject o = new JObject();
            JsonReader reader = o.CreateReader();
            while (reader.Read())
            {   
            }

            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartArray();

            writer.WriteToken(reader);

            Assert.AreEqual(WriteState.Array, writer.WriteState);

            writer.WriteEndArray();

            StringAssert.AreEqual(@"[]", writer.Token.ToString());
        }
Пример #7
0
        public void WriteTokenWithParent()
        {
            JObject o = new JObject
            {
                ["prop1"] = new JArray(1),
                ["prop2"] = 1
            };

            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartArray();

            writer.WriteToken(o.CreateReader());

            Assert.AreEqual(WriteState.Array, writer.WriteState);

            writer.WriteEndArray();

            Console.WriteLine(writer.Token.ToString());

            StringAssert.AreEqual(@"[
  {
    ""prop1"": [
      1
    ],
    ""prop2"": 1
  }
]", writer.Token.ToString());
        }
Пример #8
0
        public void WriteTokenWithPropertyParent()
        {
            JValue v = new JValue(1);

            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartObject();
            writer.WritePropertyName("Prop1");

            writer.WriteToken(v.CreateReader());

            Assert.AreEqual(WriteState.Object, writer.WriteState);

            writer.WriteEndObject();

            StringAssert.AreEqual(@"{
  ""Prop1"": 1
}", writer.Token.ToString());
        }
Пример #9
0
 private JToken CreateJObject(JsonReader reader)
 {
   ValidationUtils.ArgumentNotNull((object) reader, "reader");
   using (JTokenWriter jtokenWriter = new JTokenWriter())
   {
     jtokenWriter.WriteStartObject();
     if (reader.TokenType == JsonToken.PropertyName)
       jtokenWriter.WriteToken(reader, reader.Depth - 1);
     else
       jtokenWriter.WriteEndObject();
     return jtokenWriter.Token;
   }
 }
Пример #10
0
 private JToken CreateJToken(JsonReader reader, JsonContract contract)
 {
   ValidationUtils.ArgumentNotNull((object) reader, "reader");
   if (contract != null && contract.UnderlyingType == typeof (JRaw))
     return (JToken) JRaw.Create(reader);
   using (JTokenWriter jtokenWriter = new JTokenWriter())
   {
     jtokenWriter.WriteToken(reader);
     return jtokenWriter.Token;
   }
 }
        private JToken CreateJToken(JsonReader reader)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");

              JToken token;
              using (JTokenWriter writer = new JTokenWriter())
              {
            writer.WriteToken(reader);
            token = writer.Token;
              }

              return token;
        }
        private JToken CreateJObject(JsonReader reader)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");

            //          throw new Exception("Expected current token of type {0}, got {1}.".FormatWith(CultureInfo.InvariantCulture, JsonToken.PropertyName, reader.TokenType));

              JToken token;
              using (JTokenWriter writer = new JTokenWriter())
              {
            writer.WriteStartObject();

            if (reader.TokenType == JsonToken.PropertyName)
              writer.WriteToken(reader, reader.Depth - 1);
            else
              writer.WriteEndObject();

            token = writer.Token;
              }

              return token;
        }
 // Token: 0x06000BBB RID: 3003
 // RVA: 0x0004388C File Offset: 0x00041A8C
 private JToken CreateJObject(JsonReader reader)
 {
     ValidationUtils.ArgumentNotNull(reader, "reader");
     JToken token;
     using (JTokenWriter jTokenWriter = new JTokenWriter())
     {
         jTokenWriter.WriteStartObject();
         while (true)
         {
             if (reader.TokenType == JsonToken.PropertyName)
             {
                 string text = (string)reader.Value;
                 while (reader.Read())
                 {
                     if (reader.TokenType != JsonToken.Comment)
                     {
                         break;
                     }
                 }
                 if (!this.CheckPropertyName(reader, text))
                 {
                     jTokenWriter.WritePropertyName(text);
                     jTokenWriter.WriteToken(reader, true, true);
                 }
             }
             else if (reader.TokenType != JsonToken.Comment)
             {
                 break;
             }
             if (!reader.Read())
             {
                 goto Block_4;
             }
         }
         jTokenWriter.WriteEndObject();
         token = jTokenWriter.Token;
         return token;
         Block_4:
         throw JsonSerializationException.Create(reader, "Unexpected end when deserializing object.");
     }
     return token;
 }