FractionJsonExtensions Class
Definition
- Assembly
- Bodu.Numerics.Serialization.Json.dll
- Package
- Bodu.Numerics.Serialization.Json 1.0.0
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
jsonstringThe JSON text to deserialize.
policyNumericsJsonPolicyThe serialization shape to expect. Defaults to Strict.
Returns
- Fraction<T>
The rational value the JSON text represents.
Type Parameters
TThe backing integer type of the fraction.
Exceptions
- ArgumentNullException
jsonis null.- JsonException
jsonis not a valid fraction underpolicy.
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
valueFraction<T>The rational value to serialize.
policyNumericsJsonPolicyThe serialization shape to apply. Defaults to Strict.
Returns
- string
The JSON text representing
value.
Type Parameters
TThe backing integer type of the fraction.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |