Table of Contents

DiscreteIntervalJsonConverter<T> Class

Definition

Namespace
Bodu.Numerics.Serialization.Json
Assembly
Bodu.Numerics.Serialization.Json.dll
Package
Bodu.Numerics.Serialization.Json 1.0.0
Source
DiscreteIntervalJsonConverter{T}.cs

Converts a DiscreteInterval<T> to and from JSON using the policy supplied at construction.

public sealed class DiscreteIntervalJsonConverter<T> : JsonConverter<DiscreteInterval<T>> where T : IBinaryInteger<T>

Type Parameters

T

The backing integer type of the interval.

Inheritance
DiscreteIntervalJsonConverter<T>
Inherited Members
Extension Methods

Remarks

A DiscreteInterval<T> is canonically a closed integer interval, so it serializes through the continuous Interval<T> converter over its ToInterval() projection and is read back with FromInterval(Interval<T>), which snaps any open bounds inward to the contained integers. The wire shape therefore matches IntervalJsonConverter<T> under the same NumericsJsonPolicy - the Compact form of [1, 5], the object form for Strict / Lenient, the unbounded markers, and the empty-set representation.

Constructors

DiscreteIntervalJsonConverter()

Initializes a new instance of the DiscreteIntervalJsonConverter<T> class configured for the Strict shape.

public DiscreteIntervalJsonConverter()

DiscreteIntervalJsonConverter(NumericsJsonPolicy)

Initializes a new instance of the DiscreteIntervalJsonConverter<T> class configured for the supplied policy.

public DiscreteIntervalJsonConverter(NumericsJsonPolicy policy)

Parameters

policy NumericsJsonPolicy

The serialization policy.

Exceptions

ArgumentOutOfRangeException

policy is not a defined NumericsJsonPolicy value.

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to type DiscreteInterval.

public override DiscreteInterval<T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)

Parameters

reader Utf8JsonReader

The reader.

typeToConvert Type

The type to convert.

options JsonSerializerOptions

An object that specifies serialization options to use.

Returns

DiscreteInterval<T>

The converted value.

Write(Utf8JsonWriter, DiscreteInterval<T>, JsonSerializerOptions)

Writes a specified value as JSON.

public override void Write(Utf8JsonWriter writer, DiscreteInterval<T> value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter

The writer to write to.

value DiscreteInterval<T>

The value to convert to JSON.

options JsonSerializerOptions

An object that specifies serialization options to use.

Applies to

ProductVersions
.NET8, 10