Table of Contents

Class TimeSpanConverter

Namespace
VpnHood.Net.Toolkit.Converters
Assembly
VpnHood.Net.Toolkit.dll

Converts a TimeSpan to its text form, such as 00:05:00, and reads that form or a number of seconds.

public class TimeSpanConverter : JsonConverter<TimeSpan>
Inheritance
TimeSpanConverter
Inherited Members

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to type TimeSpan.

public override TimeSpan 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

TimeSpan

The converted value.

Exceptions

FormatException

The text is not a time interval.

ArgumentNullException

The value is null.

OverflowException

The interval is too long.

InvalidOperationException

The value is neither a number nor a string.

Write(Utf8JsonWriter, TimeSpan, JsonSerializerOptions)

Writes a specified value as JSON.

public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter

The writer to write to.

value TimeSpan

The value to convert to JSON.

options JsonSerializerOptions

An object that specifies serialization options to use.