Table of Contents

FractionJsonExtensions Class

Definition

Namespace
Bodu.Numerics.Serialization.Json
Assembly
Bodu.Numerics.Serialization.Json.dll
Package
Bodu.Numerics.Serialization.Json 1.0.0
Source
FractionJsonExtensions.cs

Convenience JSON helpers for Fraction<T> that serialize through the Bodu.Numerics converters under a chosen NumericsJsonPolicy.

public static class FractionJsonExtensions
Inheritance
FractionJsonExtensions
Inherited Members

Remarks

These helpers moved here from the core library so that Bodu.Numerics takes no dependency on System.Text.Json. Each call configures a fresh JsonSerializerOptions and registers the numeric converters; for repeated serialization prefer building one JsonSerializerOptions with AddNumericsJsonConverters(JsonSerializerOptions, NumericsJsonPolicy) and reusing it.

Methods

FromJson<T>(string, NumericsJsonPolicy)

Deserializes a Fraction<T> from its JSON representation under the supplied policy.

[RequiresUnreferencedCode("JSON deserialization of Fraction<T> uses the reflection-based JsonSerializer. Use a source-generated JsonSerializerContext for trimming and AOT.")]
[RequiresDynamicCode("JSON deserialization of Fraction<T> uses the reflection-based JsonSerializer. Use a source-generated JsonSerializerContext for trimming and AOT.")]
public static Fraction<T> FromJson<T>(string json, NumericsJsonPolicy policy = NumericsJsonPolicy.Strict) where T : IBinaryInteger<T>

Parameters

json string

The JSON text to deserialize.

policy NumericsJsonPolicy

The serialization shape to expect. Defaults to Strict.

Returns

Fraction<T>

The rational value the JSON text represents.

Type Parameters

T

The backing integer type of the fraction.

Exceptions

ArgumentNullException

json is null.

JsonException

json is not a valid fraction under policy.

ToJson<T>(Fraction<T>, NumericsJsonPolicy)

Serializes this rational value to JSON under the supplied policy.

[RequiresUnreferencedCode("JSON serialization of Fraction<T> uses the reflection-based JsonSerializer. Use a source-generated JsonSerializerContext for trimming and AOT.")]
[RequiresDynamicCode("JSON serialization of Fraction<T> uses the reflection-based JsonSerializer. Use a source-generated JsonSerializerContext for trimming and AOT.")]
public static string ToJson<T>(this Fraction<T> value, NumericsJsonPolicy policy = NumericsJsonPolicy.Strict) where T : IBinaryInteger<T>

Parameters

value Fraction<T>

The rational value to serialize.

policy NumericsJsonPolicy

The serialization shape to apply. Defaults to Strict.

Returns

string

The JSON text representing value.

Type Parameters

T

The backing integer type of the fraction.

Applies to

ProductVersions
.NET8, 10