Class DelegatingConverterBase<T>
Converter which does nothing but delegate to another one for all operations.
Since 1.0.x
Availability net6.0, netstandard2.0
Inherited Members
Namespace: NodaTime.Serialization.SystemTextJson
Assembly: NodaTime.Serialization.SystemTextJson.dll
Syntax
public abstract class DelegatingConverterBase<T> : JsonConverter<T>
Type Parameters
Name | Description |
---|---|
T | The type of object or value handled by the converter. |
Remarks
Nothing in this class is specific to Noda Time. Its purpose is to make it easy
to reuse other converter instances with LocalDate,
which can only identify a converter by type.
Examples
If you had some JsonConverterAttribute properties which needed one converter, but others that needed another, you might want to have different types implementing those converters. Each type would just derive from this, passing the right converter into the base constructor.
public sealed class ShortDateConverter : DelegatingConverterBase
{
public ShortDateConverter() : base(NodaConverters.LocalDateConverter) {}
}
Constructors
DelegatingConverterBase(JsonConverter<T>)
Constructs a converter delegating to
original
.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
protected DelegatingConverterBase(JsonConverter<T> original)
Parameters
Type | Name | Description |
---|---|---|
JsonConverter<T> | original | The converter to delegate to. Must not be null. |
Methods
CanConvert(Type)
Determines whether the specified type can be converted.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public override bool CanConvert(Type objectType)
Parameters
Type | Name | Description |
---|---|---|
Type | objectType |
Returns
Type | Description |
---|---|
bool | true if the type can be converted; otherwise, false. |
Overrides
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads and converts the JSON to type
T
.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
Type | Name | Description |
---|---|---|
Utf8JsonReader | reader | The reader. |
Type | typeToConvert | The type to convert. |
JsonSerializerOptions | options | An object that specifies serialization options to use. |
Returns
Type | Description |
---|---|
T | The converted value. |
Overrides
Write(Utf8JsonWriter, T, JsonSerializerOptions)
Writes a specified value as JSON.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
Parameters
Type | Name | Description |
---|---|---|
Utf8JsonWriter | writer | The writer to write to. |
T | value | The value to convert to JSON. |
JsonSerializerOptions | options | An object that specifies serialization options to use. |