DiscreteIntervalJsonConverter<T> Class
Definition
- Assembly
- Bodu.Numerics.Serialization.Json.dll
- Package
- Bodu.Numerics.Serialization.Json 1.0.0
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
TThe 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
policyNumericsJsonPolicyThe serialization policy.
Exceptions
- ArgumentOutOfRangeException
policyis 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
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn 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
writerUtf8JsonWriterThe writer to write to.
valueDiscreteInterval<T>The value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |