Newtonsoft.Json.JsonTextReader.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 override decimal? ReadAsDecimal()
        {
            return (decimal?)ReadNumberValue(ReadType.ReadAsDecimal);
        }

Usage Example

        public void ReadInvalidNonBase10Number()
        {
            string json = "0aq2dun13.hod";

            JsonTextReader reader = new JsonTextReader(new StringReader(json));

            ExceptionAssert.Throws<JsonReaderException>("Input string '0a' is not a valid number. Path '', line 1, position 2.",
                () => { reader.Read(); });

            reader = new JsonTextReader(new StringReader(json));

            ExceptionAssert.Throws<JsonReaderException>("Input string '0a' is not a valid decimal. Path '', line 1, position 2.",
                () => { reader.ReadAsDecimal(); });

            reader = new JsonTextReader(new StringReader(json));

            ExceptionAssert.Throws<JsonReaderException>("Input string '0a' is not a valid integer. Path '', line 1, position 2.",
                () => { reader.ReadAsInt32(); });
        }
All Usage Examples Of Newtonsoft.Json.JsonTextReader::ReadAsDecimal