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
readerUtf8JsonReaderThe JSON reader to read from.
typeToConvertTypeThe type to convert to.
optionsJsonSerializerOptionsThe 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
writerUtf8JsonWriterThe JSON writer to write to.
valueTimeSpanThe TimeSpan value to write.
optionsJsonSerializerOptionsThe JSON serializer options.