Newtonsoft.Json.JsonReader.ReadAsDecimal C# (CSharp) Method

ReadAsDecimal() public method

Reads the next JSON token from the stream as a Nullable{T} of Decimal.
public ReadAsDecimal ( ) : decimal?
return decimal?
        public virtual decimal? ReadAsDecimal()
        {
            JsonToken t = GetContentToken();

            switch (t)
            {
                case JsonToken.None:
                case JsonToken.Null:
                case JsonToken.EndArray:
                    return null;
                case JsonToken.Integer:
                case JsonToken.Float:
                    if (!(Value is decimal))
                    {
                        SetToken(JsonToken.Float, Convert.ToDecimal(Value, CultureInfo.InvariantCulture), false);
                    }

                    return (decimal)Value;
                case JsonToken.String:
                    return ReadDecimalString((string)Value);
            }

            throw JsonReaderException.Create(this, "Error reading decimal. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, t));
        }

Usage Example

示例#1
0
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     var extent = (Extent)existingValue;
     decimal? d;
     d = reader.ReadAsDecimal();
     d = reader.ReadAsDecimal();
     d = reader.ReadAsDecimal();
     d = reader.ReadAsDecimal();
     return existingValue;
 }
All Usage Examples Of Newtonsoft.Json.JsonReader::ReadAsDecimal