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
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn 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
writerUtf8JsonWriterThe writer to write to.
valueTimeSpanThe value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.