Beispiel #1
0
 internal string ReadAsStringInternal()
 {
     this._readType = ReadType.ReadAsString;
     while (this.ReadInternal())
     {
         if (this.TokenType != JsonToken.Comment)
         {
             if (this.TokenType == JsonToken.String)
             {
                 return((string)this.Value);
             }
             if (this.TokenType == JsonToken.Null)
             {
                 return((string)null);
             }
             if (JsonReader.IsPrimitiveToken(this.TokenType) && this.Value != null)
             {
                 string str = !ConvertUtils.IsConvertible(this.Value) ? (!(this.Value is IFormattable) ? this.Value.ToString() : ((IFormattable)this.Value).ToString((string)null, (IFormatProvider)this.Culture)) : ConvertUtils.ToConvertible(this.Value).ToString((IFormatProvider)this.Culture);
                 this.SetToken(JsonToken.String, (object)str);
                 return(str);
             }
             else if (this.TokenType == JsonToken.EndArray)
             {
                 return((string)null);
             }
             else
             {
                 throw JsonReaderException.Create(this, StringUtils.FormatWith("Error reading string. Unexpected token: {0}.", (IFormatProvider)CultureInfo.InvariantCulture, (object)this.TokenType));
             }
         }
     }
     this.SetToken(JsonToken.None);
     return((string)null);
 }
Beispiel #2
0
 internal string ReadAsStringInternal()
 {
     this._readType = ReadType.ReadAsString;
     while (this.ReadInternal())
     {
         JsonToken tokenType = this.TokenType;
         if (tokenType != JsonToken.Comment)
         {
             if (tokenType == JsonToken.String)
             {
                 return((string)this.Value);
             }
             if (tokenType == JsonToken.Null)
             {
                 return(null);
             }
             if (JsonReader.IsPrimitiveToken(tokenType) && this.Value != null)
             {
                 string text;
                 if (this.Value is IFormattable)
                 {
                     text = ((IFormattable)this.Value).ToString(null, this.Culture);
                 }
                 else
                 {
                     text = this.Value.ToString();
                 }
                 this.SetToken(JsonToken.String, text);
                 return(text);
             }
             if (tokenType == JsonToken.EndArray)
             {
                 return(null);
             }
             throw JsonReaderException.Create(this, "Error reading string. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, tokenType));
         }
     }
     this.SetToken(JsonToken.None);
     return(null);
 }