Table of Contents

Class TimeSpanFromSecondsConverter

Namespace
Crews.PlanningCenter.Api.Converters
Assembly
Crews.PlanningCenter.Api.dll

A JSON converter that converts a string or number representing seconds into a TimeSpan object, and converts a TimeSpan object back into a number of seconds when writing JSON.

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

Constructors

TimeSpanFromSecondsConverter()

public TimeSpanFromSecondsConverter()

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads a JSON value and converts it to a TimeSpan object. The JSON value can be either a string or a number representing seconds.

public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)

Parameters

reader Utf8JsonReader

The JSON reader to read from.

typeToConvert Type

The type to convert to.

options JsonSerializerOptions

The JSON serializer options.

Returns

TimeSpan

The converted TimeSpan value.

Exceptions

JsonException

Thrown when the value cannot be converted to a TimeSpan.

Write(Utf8JsonWriter, TimeSpan, JsonSerializerOptions)

Writes a TimeSpan value as a number of seconds to JSON.

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

Parameters

writer Utf8JsonWriter

The JSON writer to write to.

value TimeSpan

The TimeSpan value to write.

options JsonSerializerOptions

The JSON serializer options.