Table of Contents

Class JsonNumber

Namespace
Nerdbank.Json
Assembly
Nerdbank.Json.dll

A JSON number value that preserves the exact JSON token text so that no precision or formatting is lost.

public sealed class JsonNumber : JsonValue, IEquatable<JsonValue>
Inheritance
JsonNumber
Implements
Inherited Members

Constructors

JsonNumber(string)

Initializes a new instance of the JsonNumber class from a raw JSON number token.

public JsonNumber(string rawToken)

Parameters

rawToken string

The exact JSON number token, for example 1.0 or 1e10.

Properties

Kind

Gets the kind of this value.

public override JsonValueKind Kind { get; }

Property Value

JsonValueKind

RawToken

Gets the exact JSON number token text.

public string RawToken { get; }

Property Value

string

Methods

Equals(JsonValue?)

Indicates whether the current object is equal to another object of the same type.

public override bool Equals(JsonValue? other)

Parameters

other JsonValue

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

GetDecimal()

Gets the value as a decimal.

public decimal GetDecimal()

Returns

decimal

The value.

Exceptions

FormatException

Thrown if the token is not representable as a decimal.

GetDouble()

Gets the value as a double.

public double GetDouble()

Returns

double

The value.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

GetInt64()

Gets the value as a long.

public long GetInt64()

Returns

long

The value.

Exceptions

FormatException

Thrown if the token is not an integer in range.

TryGetInt64(out long)

Attempts to get the value as a long.

public bool TryGetInt64(out long value)

Parameters

value long

Receives the value.

Returns

bool

true if the token is an integer in range.