예제 #1
0
 internal static JsonReaderException Create(JsonReader reader, string message)
 {
     return Create(reader, message, null);
 }
예제 #2
0
 internal static JsonReaderException Create(JsonReader reader, string message, Exception ex)
 {
     return Create(reader as IJsonLineInfo, reader.Path, message, ex);
 }
예제 #3
0
 /// <summary>
 /// Writes the current <see cref="JsonReader"/> token and its children.
 /// </summary>
 /// <param name="reader">The <see cref="JsonReader"/> to read the token from.</param>
 public void WriteToken(JsonReader reader)
 {
     WriteToken(reader, true);
 }
예제 #4
0
        /// <summary>
        /// Writes the current <see cref="JsonReader"/> token.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read the token from.</param>
        /// <param name="writeChildren">A flag indicating whether the current token's children should be written.</param>
        public void WriteToken(JsonReader reader, bool writeChildren)
        {
            ValidationUtils.ArgumentNotNull(reader, nameof(reader));

            WriteToken(reader, writeChildren, true, true);
        }
예제 #5
0
        private void WriteConstructorDate(JsonReader reader)
        {
            if (!reader.Read())
            {
                throw JsonWriterException.Create(this, "Unexpected end when reading date constructor.", null);
            }
            if (reader.TokenType != JsonToken.Integer)
            {
                throw JsonWriterException.Create(this, "Unexpected token when reading date constructor. Expected Integer, got " + reader.TokenType, null);
            }

            long ticks = (long)reader.Value;
            DateTime date = DateTimeUtils.ConvertJavaScriptTicksToDateTime(ticks);

            if (!reader.Read())
            {
                throw JsonWriterException.Create(this, "Unexpected end when reading date constructor.", null);
            }
            if (reader.TokenType != JsonToken.EndConstructor)
            {
                throw JsonWriterException.Create(this, "Unexpected token when reading date constructor. Expected EndConstructor, got " + reader.TokenType, null);
            }

            WriteValue(date);
        }
예제 #6
0
 internal void WriteToken(JsonReader reader, int initialDepth, bool writeChildren, bool writeDateConstructorAsDate, bool writeComments)
 {
     do
     {
         // write a JValue date when the constructor is for a date
         if (writeDateConstructorAsDate && reader.TokenType == JsonToken.StartConstructor && string.Equals(reader.Value.ToString(), "Date", StringComparison.Ordinal))
         {
             WriteConstructorDate(reader);
         }
         else
         {
             if (reader.TokenType != JsonToken.Comment || writeComments)
             {
                 WriteToken(reader.TokenType, reader.Value);
             }
         }
     } while (
         // stop if we have reached the end of the token being read
         initialDepth - 1 < reader.Depth - (JsonTokenUtils.IsEndToken(reader.TokenType) ? 1 : 0)
         && writeChildren
         && reader.Read());
 }
예제 #7
0
        internal void WriteToken(JsonReader reader, bool writeChildren, bool writeDateConstructorAsDate, bool writeComments)
        {
            int initialDepth;

            if (reader.TokenType == JsonToken.None)
            {
                initialDepth = -1;
            }
            else if (!JsonTokenUtils.IsStartToken(reader.TokenType))
            {
                initialDepth = reader.Depth + 1;
            }
            else
            {
                initialDepth = reader.Depth;
            }

            WriteToken(reader, initialDepth, writeChildren, writeDateConstructorAsDate, writeComments);
        }
예제 #8
0
 /// <summary>
 /// Reads the JSON representation of the object.
 /// </summary>
 /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
 /// <param name="objectType">Type of the object.</param>
 /// <param name="existingValue">The existing value of object being read.</param>
 /// <param name="serializer">The calling serializer.</param>
 /// <returns>The object value.</returns>
 public abstract object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer);
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsonValidatingReader"/> class that
 /// validates the content returned from the given <see cref="JsonReader"/>.
 /// </summary>
 /// <param name="reader">The <see cref="JsonReader"/> to read from while validating.</param>
 public JsonValidatingReader(JsonReader reader)
 {
     ValidationUtils.ArgumentNotNull(reader, nameof(reader));
     _reader = reader;
     _stack = new Stack<SchemaScope>();
 }