Load() public static method

Loads an JConstructor from a JsonReader.
public static Load ( JsonReader reader ) : JConstructor
reader JsonReader A that will be read for the content of the .
return JConstructor
Exemplo n.º 1
0
 public static JToken ReadFrom(JsonReader reader)
 {
     ValidationUtils.ArgumentNotNull((object)reader, "reader");
     if (reader.TokenType == JsonToken.None && !reader.Read())
     {
         throw JsonReaderException.Create(reader, "Error reading JToken from JsonReader.");
     }
     if (reader.TokenType == JsonToken.StartObject)
     {
         return((JToken)JObject.Load(reader));
     }
     if (reader.TokenType == JsonToken.StartArray)
     {
         return((JToken)JArray.Load(reader));
     }
     if (reader.TokenType == JsonToken.PropertyName)
     {
         return((JToken)JProperty.Load(reader));
     }
     if (reader.TokenType == JsonToken.StartConstructor)
     {
         return((JToken)JConstructor.Load(reader));
     }
     if (!JsonReader.IsStartToken(reader.TokenType))
     {
         return((JToken) new JValue(reader.Value));
     }
     else
     {
         throw JsonReaderException.Create(reader, StringUtils.FormatWith("Error reading JToken from JsonReader. Unexpected token: {0}", (IFormatProvider)CultureInfo.InvariantCulture, (object)reader.TokenType));
     }
 }
Exemplo n.º 2
0
 public static JToken ReadFrom(JsonReader reader)
 {
     ValidationUtils.ArgumentNotNull(reader, "reader");
     if (reader.TokenType == JsonToken.None && !reader.Read())
     {
         throw new Exception("Error reading JToken from JsonReader.");
     }
     if (reader.TokenType == JsonToken.StartObject)
     {
         return(JObject.Load(reader));
     }
     if (reader.TokenType == JsonToken.StartArray)
     {
         return(JArray.Load(reader));
     }
     if (reader.TokenType == JsonToken.PropertyName)
     {
         return(JProperty.Load(reader));
     }
     if (reader.TokenType == JsonToken.StartConstructor)
     {
         return(JConstructor.Load(reader));
     }
     if (!JsonReader.IsStartToken(reader.TokenType))
     {
         return(new JValue(reader.Value));
     }
     throw new Exception("Error reading JToken from JsonReader. Unexpected token: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
 }
Exemplo n.º 3
0
        /// <summary>
        /// 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>
        /// <returns>
        /// An <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 JToken ReadFrom(JsonReader reader)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");

            if (reader.TokenType == JsonToken.None)
            {
                if (!reader.Read())
                {
                    throw new Exception("Error reading JToken from JsonReader.");
                }
            }

            if (reader.TokenType == JsonToken.StartObject)
            {
                return(JObject.Load(reader));
            }

            if (reader.TokenType == JsonToken.StartArray)
            {
                return(JArray.Load(reader));
            }

            if (reader.TokenType == JsonToken.PropertyName)
            {
                return(JProperty.Load(reader));
            }

            if (reader.TokenType == JsonToken.StartConstructor)
            {
                return(JConstructor.Load(reader));
            }

            // hack. change to look at TokenType rather than using value
            if (!JsonReader.IsStartToken(reader.TokenType))
            {
                return(new JValue(reader.Value));
            }

            // TODO: loading constructor and parameters?
            throw new Exception("Error reading JToken from JsonReader. Unexpected token: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
        }
Exemplo n.º 4
0
 public static new JConstructor Load(JsonReader reader)
 {
     return(JConstructor.Load(reader, null));
 }
Exemplo n.º 5
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));
 }